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

MOD = 10**9+7

a = [[0 for j in range(M+1)] for i in range(N+1)]

for i in range(N+1) :
    for j in range(M+1) :
        if i == 0 or j == 0 :
            a[i][j] = 1
        else :
            a[i][j] = a[i-1][j] + a[i][j-1] - (a[i-1][j-1] if S[i-1] != T[j-1] else 0)
            a[i][j] %= MOD

print(a[N][M]) 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 MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 [0 for j in range(M+1)] for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [0 for j in range(M+1)] a = [[0 for j in range(M+1)] for i in range(N+1)] a [[0 for j in range(M+1)] for i in range(N+1)] for i in range(N+1) :
    for j in range(M+1) :
        if i == 0 or j == 0 :
            a[i][j] = 1
        else :
            a[i][j] = a[i-1][j] + a[i][j-1] - (a[i-1][j-1] if S[i-1] != T[j-1] else 0)
            a[i][j] %= MOD i range(N+1) range N+1 N 1 for j in range(M+1) :
        if i == 0 or j == 0 :
            a[i][j] = 1
        else :
            a[i][j] = a[i-1][j] + a[i][j-1] - (a[i-1][j-1] if S[i-1] != T[j-1] else 0)
            a[i][j] %= MOD j range(M+1) range M+1 M 1 if i == 0 or j == 0 :
            a[i][j] = 1
        else :
            a[i][j] = a[i-1][j] + a[i][j-1] - (a[i-1][j-1] if S[i-1] != T[j-1] else 0)
            a[i][j] %= MOD i == 0 or j == 0 i == 0 i 0 j == 0 j 0 a[i][j] = 1 a[i][j] [i] a i j 1 a[i][j] = a[i-1][j] + a[i][j-1] - (a[i-1][j-1] if S[i-1] != T[j-1] else 0) a[i][j] [i] a i j a[i-1][j] + a[i][j-1] - (a[i-1][j-1] if S[i-1] != T[j-1] else 0) a[i-1][j] + a[i][j-1] a[i-1][j] [i-1] a i-1 i 1 j a[i][j-1] [i] a i j-1 j 1 a[i-1][j-1] if S[i-1] != T[j-1] else 0 S[i-1] != T[j-1] S[i-1] S i-1 i 1 T[j-1] T j-1 j 1 a[i-1][j-1] [i-1] a i-1 i 1 j-1 j 1 0 a[i][j] %= MOD a[i][j] [i] a i j MOD print(a[N][M]) print a[N][M] [N] a N M N,M = map(int,input().split()) map(int,input().split()) N T = list(map(int,input().split())) list(map(int,input().split())) T S = list(map(int,input().split())) list(map(int,input().split())) S M = map(int,input().split()) map(int,input().split()) M a = [[0 for j in range(M+1)] for i in range(N+1)] [[0 for j in range(M+1)] for i in range(N+1)] a MOD = 10**9+7 10**9+7 MOD
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

MOD = 10**9+7

a = [[0 for j in range(M+1)] for i in range(N+1)]

for i in range(N+1) :
    for j in range(M+1) :
        if i == 0 or j == 0 :
            a[i][j] = 1
        else :
            a[i][j] = a[i-1][j] + a[i][j-1] - (a[i-1][j-1] if S[i-1] != T[j-1] else 0)
            a[i][j] %= MOD

print(a[N][M])
