from collections import defaultdict
import bisect
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
mod = 10**9+7
p = max(n,m)
if n>m:
  t.extend((0,)*(n-m))
else:
  s.extend((0,)*(m-n))
dp = [[1 for i in range(p+1)] for j in range(p+1)]
for i in range(1,p+1):
  for j in range(1,p+1):
    x = s[i-1]
    y = t[j-1]
    if x == y:
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod
    else:
      dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod
print(dp[-1][-1]) from collections import defaultdict import bisect bisect 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 p = max(n,m) p max(n,m) max n m if n>m:
  t.extend((0,)*(n-m))
else:
  s.extend((0,)*(m-n)) n>m n m t.extend((0,)*(n-m)) t.extend t extend (0,)*(n-m) 0 n-m n m s.extend((0,)*(m-n)) s.extend s extend (0,)*(m-n) 0 m-n m n [1 for i in range(p+1)] for j in range(p+1) for j in range(p+1) j range(p+1) range p+1 p 1 for j in range(p+1) [1 for i in range(p+1)] dp = [[1 for i in range(p+1)] for j in range(p+1)] dp [[1 for i in range(p+1)] for j in range(p+1)] for i in range(1,p+1):
  for j in range(1,p+1):
    x = s[i-1]
    y = t[j-1]
    if x == y:
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod
    else:
      dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod i range(1,p+1) range 1 p+1 p 1 for j in range(1,p+1):
    x = s[i-1]
    y = t[j-1]
    if x == y:
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod
    else:
      dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod j range(1,p+1) range 1 p+1 p 1 x = s[i-1] x s[i-1] s i-1 i 1 y = t[j-1] y t[j-1] t j-1 j 1 if x == y:
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod
    else:
      dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod x == y x y dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod dp[i][j] [i] dp i j (dp[i-1][j]+dp[i][j-1])%mod dp[i-1][j]+dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 mod dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod dp[i][j] [i] dp i j (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1] dp[i][j-1]+dp[i-1][j] dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j] [i-1] dp i-1 i 1 j dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 mod print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 p = max(n,m) max(n,m) p dp = [[1 for i in range(p+1)] for j in range(p+1)] [[1 for i in range(p+1)] for j in range(p+1)] dp y = t[j-1] t[j-1] y m = map(int,input().split()) map(int,input().split()) 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 mod = 10**9+7 10**9+7 mod x = s[i-1] s[i-1] x
from collections import defaultdict
import bisect
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
mod = 10**9+7
p = max(n,m)
if n>m:
  t.extend((0,)*(n-m))
else:
  s.extend((0,)*(m-n))
dp = [[1 for i in range(p+1)] for j in range(p+1)]
for i in range(1,p+1):
  for j in range(1,p+1):
    x = s[i-1]
    y = t[j-1]
    if x == y:
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod
    else:
      dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod
print(dp[-1][-1])