import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, M= LI()
    if N > M:
        S = LI()
        T = LI()
    else:
        T = LI()
        S = LI()
    # 以下、必ず S のほうが長い状態。

    # とりあえず愚直に組んでみる。
    import itertools
    counter = 0
    for i in range(len(T) + 1):   # 短いほうでループを回す
        for x in itertools.combinations(S, i):
            for y in itertools.combinations(T, i):
                if x == y: 
                    counter += 1
                    counter //= MOD

    print(counter)

main()