N,M = map(int,input().split())
s = []
p = []
for i in range(M):
    s.append([int(i) for i in input().split()])
p.append(map(int,input().split()))
cnt = 0
for i in s:
    for j in i:
        for t in range(len(p)):
            if (j // 2) == p[t]:
                cnt+=1
print(cnt)