## @error36
Serial_list = input().split(" ")
a = Serial_list[0]
b = Serial_list[1]
ans = 0
for i in range(int(input())):
# 建立統計清單
total_dic = {}
total_dic[a] = 0
total_dic[b] = 0
# 輸入資料
PurchaseRecord = input().split(" ")
for d in PurchaseRecord:
# 建立條目
number = int(d)
key = str(abs(number))
if key not in total_dic.keys():
total_dic[key] = 0
# 新增條目資訊
if number > 0:
total_dic[key] += 1
elif number < 0:
total_dic[key] += -1
# 搜索並統計
if total_dic[a] > 0 and total_dic[b] > 0:
ans += 1
print(ans)