N,M = map(int,input().split())
*S, = map(int,input().split())
*T, = map(int,input().split())

import itertools

S_bubun = []
T_bubun = []
for i in range(N+1):
    S_bubun.extend(list(itertools.combinations(S,i)))
for i in range(M+1):
    T_bubun.extend(list(itertools.combinations(T,i)))

count = 0
for s in S_bubun:
    for t in T_bubun:
        if s == t:
            count += 1

print(count %(10**9 + 7))