import itertools
n,m = map(int, input().split())
lists = list(map(int,input().split()))
listt = list(map(int,input().split()))
c = 0
for i in range(min(n,m)+1):
    s = list(itertools.combinations(lists,i))
    t = list(itertools.combinations(listt,i))
    for j in range(len(s)):
        if s[j] in t:
            c = c+t.count(s[j])
print(c)