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

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

ta = [[0] * (M+1) for i in range(N+1)]
ta[0][0]=1
wa = [[0] * (M+1) for i in range(N+1)]
wa[0][:]=[1]*(M+1)
for i in range(N+1):
    wa[i][0]=1
output = 1
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            ta[i][j]=wa[i-1][j-1]
            wa[i][j]=(wa[i-1][j]+wa[i][j-1])%(10**9+7)
        else:
            wa[i][j]=(wa[i-1][j]+wa[i][j-1]-wa[i-1][j-1]+(10**9+7))%(10**9+7)
output = wa[N][M]
print(int(output))