D = 10**9+7
N, M = list(map(int,raw_input().split()))
S = list(map(int,raw_input().split()))
T = list(map(int,raw_input().split()))
a = [[0 for j in xrange(M+1)] for i in xrange(N+1)]
for i in xrange(N+1):
  a[i][0] = 1
for j in xrange(M+1):
  a[0][j] = 1
for i in xrange(N):
  for j in xrange(M):
    a[i+1][j+1] = (a[i][j+1]+a[i+1][j])%D
    if S[i]!=T[j]:
      a[i+1][j+1] = (a[i+1][j+1]-a[i][j])%D
print(a[N][M]) D = 10**9+7 D 10**9+7 10**9 10 9 7 N, M = list(map(int,raw_input().split())) N list(map(int,raw_input().split())) list map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split M S = list(map(int,raw_input().split())) S list(map(int,raw_input().split())) list map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split T = list(map(int,raw_input().split())) T list(map(int,raw_input().split())) list map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split [0 for j in xrange(M+1)] for i in xrange(N+1) for i in xrange(N+1) i xrange(N+1) xrange N+1 N 1 for i in xrange(N+1) [0 for j in xrange(M+1)] a = [[0 for j in xrange(M+1)] for i in xrange(N+1)] a [[0 for j in xrange(M+1)] for i in xrange(N+1)] for i in xrange(N+1):
  a[i][0] = 1 i xrange(N+1) xrange N+1 N 1 a[i][0] = 1 a[i][0] [i] a i 0 1 for j in xrange(M+1):
  a[0][j] = 1 j xrange(M+1) xrange M+1 M 1 a[0][j] = 1 a[0][j] [0] a 0 j 1 for i in xrange(N):
  for j in xrange(M):
    a[i+1][j+1] = (a[i][j+1]+a[i+1][j])%D
    if S[i]!=T[j]:
      a[i+1][j+1] = (a[i+1][j+1]-a[i][j])%D i xrange(N) xrange N for j in xrange(M):
    a[i+1][j+1] = (a[i][j+1]+a[i+1][j])%D
    if S[i]!=T[j]:
      a[i+1][j+1] = (a[i+1][j+1]-a[i][j])%D j xrange(M) xrange M a[i+1][j+1] = (a[i][j+1]+a[i+1][j])%D a[i+1][j+1] [i+1] a i+1 i 1 j+1 j 1 (a[i][j+1]+a[i+1][j])%D a[i][j+1]+a[i+1][j] a[i][j+1] [i] a i j+1 j 1 a[i+1][j] [i+1] a i+1 i 1 j D if S[i]!=T[j]:
      a[i+1][j+1] = (a[i+1][j+1]-a[i][j])%D S[i]!=T[j] S[i] S i T[j] T j a[i+1][j+1] = (a[i+1][j+1]-a[i][j])%D a[i+1][j+1] [i+1] a i+1 i 1 j+1 j 1 (a[i+1][j+1]-a[i][j])%D a[i+1][j+1]-a[i][j] a[i+1][j+1] [i+1] a i+1 i 1 j+1 j 1 a[i][j] [i] a i j D print(a[N][M]) print a[N][M] [N] a N M a = [[0 for j in xrange(M+1)] for i in xrange(N+1)] [[0 for j in xrange(M+1)] for i in xrange(N+1)] a S = list(map(int,raw_input().split())) list(map(int,raw_input().split())) S T = list(map(int,raw_input().split())) list(map(int,raw_input().split())) T D = 10**9+7 10**9+7 D M = list(map(int,raw_input().split())) list(map(int,raw_input().split())) M N, M = list(map(int,raw_input().split())) list(map(int,raw_input().split())) N
D = 10**9+7
N, M = list(map(int,raw_input().split()))
S = list(map(int,raw_input().split()))
T = list(map(int,raw_input().split()))
a = [[0 for j in xrange(M+1)] for i in xrange(N+1)]
for i in xrange(N+1):
  a[i][0] = 1
for j in xrange(M+1):
  a[0][j] = 1
for i in xrange(N):
  for j in xrange(M):
    a[i+1][j+1] = (a[i][j+1]+a[i+1][j])%D
    if S[i]!=T[j]:
      a[i+1][j+1] = (a[i+1][j+1]-a[i][j])%D
print(a[N][M])