import copy
N,M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
ds={"":1}
dt={"":1}
for x in S:
    temp = ds.copy()
    for y in temp.keys():
        key = y+str(x)+" "
        if key not in ds:
            ds[key]=0
        ds[key]+=temp[y]
        #print(key,"increase",temp[y])
for x in T:
    temp = dt.copy()
    for y in temp.keys():
        key = y+str(x)+" "
        if key not in dt:
            dt[key]=0
        dt[key]+=temp[y]
        #print(key,"increase",temp[y])
answer=0
for x in dt.keys():
    if x in ds.keys():
        answer+=ds[x]*dt[x]
        #print(x,":",ds[x],"*",dt[x])
print(answer%(10**9+7))