
N,M = map(int,input().split())

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


ans = [[0] * (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:
            ans[i][j] = 1

        elif S[i-1] == T[j-1]:
            ans[i][j] = ans[i-1][j] + ans[i][j-1]

        else:
            ans[i][j] = ans[i-1][j] + ans[i][j-1] - ans[i-1][j-1]

        ans[i][j] %= (10 ** 9 + 7)

print (ans[-1][-1]) 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 [0] * (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] * (M+1) [0] 0 M+1 M 1 ans = [[0] * (M+1) for i in range(N+1)] ans [[0] * (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:
            ans[i][j] = 1

        elif S[i-1] == T[j-1]:
            ans[i][j] = ans[i-1][j] + ans[i][j-1]

        else:
            ans[i][j] = ans[i-1][j] + ans[i][j-1] - ans[i-1][j-1]

        ans[i][j] %= (10 ** 9 + 7) i range(N+1) range N+1 N 1 for j in range(M+1):

        if i == 0 or j == 0:
            ans[i][j] = 1

        elif S[i-1] == T[j-1]:
            ans[i][j] = ans[i-1][j] + ans[i][j-1]

        else:
            ans[i][j] = ans[i-1][j] + ans[i][j-1] - ans[i-1][j-1]

        ans[i][j] %= (10 ** 9 + 7) j range(M+1) range M+1 M 1 if i == 0 or j == 0:
            ans[i][j] = 1

        elif S[i-1] == T[j-1]:
            ans[i][j] = ans[i-1][j] + ans[i][j-1]

        else:
            ans[i][j] = ans[i-1][j] + ans[i][j-1] - ans[i-1][j-1]

         i == 0 or j == 0 i == 0 i 0 j == 0 j 0 ans[i][j] = 1 ans[i][j] [i] ans i j 1 elif S[i-1] == T[j-1]:
            ans[i][j] = ans[i-1][j] + ans[i][j-1]

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

N,M = map(int,input().split())

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


ans = [[0] * (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:
            ans[i][j] = 1

        elif S[i-1] == T[j-1]:
            ans[i][j] = ans[i-1][j] + ans[i][j-1]

        else:
            ans[i][j] = ans[i-1][j] + ans[i][j-1] - ans[i-1][j-1]

        ans[i][j] %= (10 ** 9 + 7)

print (ans[-1][-1])
