N, M =  map(int, input().split())
s = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
import itertools
hoges = []
for i in range(N+1):
	hoges.extend(list(itertools.combinations(s,i)))
hoget = []
for j in range(M+1):
	hoget.extend(list(itertools.combinations(t,j)))
sm = 0
for i in range(len(hoges)):
	for j in range(len(hoget)):
		if hoges[i] == hoget[j]:
			sm += 1
print(sm%(1000000007))