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

modulo = 10 ** 9 + 7

# tab[j][i] = S[i] == T[j]
tab = [[s == t for s in S] for t in T]

# 番兵
for t in tab:
    t.append(1)
tab.append([1] * (len(S) + 1))

# 右下から計算
# tab[j][i] = S[i:]とT[j:]の等しい部分列の個数
for j in range(M - 1, -1, -1):
    for i in range(N - 1, -1, -1):
        n  = tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1]  # 包除原理
        n += tab[j+1][i+1] if tab[j][i] else 0  # S[i]とT[j]をマッチさせたとき
        tab[j][i] = n % modulo

print(tab[0][0]) N, M =      map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S    = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T    = list(map(int, input().split())) T list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split modulo = 10 ** 9 + 7 modulo 10 ** 9 + 7 10 ** 9 10 9 7 [s == t for s in S] for t in T for t in T t T for t in T [s == t for s in S] tab = [[s == t for s in S] for t in T] tab [[s == t for s in S] for t in T] for t in tab:
    t.append(1) t tab t.append(1) t.append t append 1 tab.append([1] * (len(S) + 1)) tab.append tab append [1] * (len(S) + 1) [1] 1 len(S) + 1 len(S) len S 1 for j in range(M - 1, -1, -1):
    for i in range(N - 1, -1, -1):
        n  = tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1]  # 包除原理
        n += tab[j+1][i+1] if tab[j][i] else 0  # S[i]とT[j]をマッチさせたとき
        tab[j][i] = n % modulo j range(M - 1, -1, -1) range M - 1 M 1 -1 -1 for i in range(N - 1, -1, -1):
        n  = tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1]  # 包除原理
        n += tab[j+1][i+1] if tab[j][i] else 0  # S[i]とT[j]をマッチさせたとき
        tab[j][i] = n % modulo i range(N - 1, -1, -1) range N - 1 N 1 -1 -1 n  = tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1] n tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1] tab[j+1][i] + tab[j][i+1] tab[j+1][i] [j+1] tab j+1 j 1 i tab[j][i+1] [j] tab j i+1 i 1 tab[j+1][i+1] [j+1] tab j+1 j 1 i+1 i 1 n += tab[j+1][i+1] if tab[j][i] else 0 n tab[j+1][i+1] if tab[j][i] else 0 tab[j][i] [j] tab j i tab[j+1][i+1] [j+1] tab j+1 j 1 i+1 i 1 0 tab[j][i] = n % modulo tab[j][i] [j] tab j i n % modulo n modulo print(tab[0][0]) print tab[0][0] [0] tab 0 0 T    = list(map(int, input().split())) list(map(int, input().split())) T n += tab[j+1][i+1] if tab[j][i] else 0 tab[j+1][i+1] if tab[j][i] else 0 n tab = [[s == t for s in S] for t in T] [[s == t for s in S] for t in T] tab modulo = 10 ** 9 + 7 10 ** 9 + 7 modulo n  = tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1] tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1] n S    = list(map(int, input().split())) list(map(int, input().split())) S N, M =      map(int, input().split()) map(int, input().split()) N M =      map(int, input().split()) map(int, input().split()) M
N, M =      map(int, input().split())
S    = list(map(int, input().split()))
T    = list(map(int, input().split()))

modulo = 10 ** 9 + 7

# tab[j][i] = S[i] == T[j]
tab = [[s == t for s in S] for t in T]

# 番兵
for t in tab:
    t.append(1)
tab.append([1] * (len(S) + 1))

# 右下から計算
# tab[j][i] = S[i:]とT[j:]の等しい部分列の個数
for j in range(M - 1, -1, -1):
    for i in range(N - 1, -1, -1):
        n  = tab[j+1][i] + tab[j][i+1] - tab[j+1][i+1]  # 包除原理
        n += tab[j+1][i+1] if tab[j][i] else 0  # S[i]とT[j]をマッチさせたとき
        tab[j][i] = n % modulo

print(tab[0][0])
