import itertools
N,M = map(int,input().split())
# N,M = 2*10**2,2*10**2
S = list(map(int,input().split()))
T = list(map(int,input().split()))
# S = [1 for i in range(N)]
# T = [1 for i in range(N)]

MOD = 1000000007

Ss = {}
Ts = {}

for n in range(N+1):
    for k in itertools.combinations(S, n):
        if k not in Ss:
            Ss[k] = 0
        Ss[k] += 1

for n in range(M+1):
    for k in itertools.combinations(T, n):
        if k not in Ts:
            Ts[k] = 0
        Ts[k] += 1

# print(Ss)
# print(Ts)

Ss[()] = 1
Ts[()] = 1


sm = 0
for k in Ss:
    if k in Ts:
        # print(k, Ss[k], Ts[k])
        sm += Ss[k]*Ts[k]

print(sm%MOD)