import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
mod = 10**9+7
a = [0]+[int(i) for i in readline().split()]
b = [0]+[int(i) for i in readline().split()]
dp = [[0]*(m+1) for i in range(n+1)]
su = [[0]*(m+1) for i in range(n+1)]

dp[0][0] = 1
su[0][0] = 1
for i in range(1,n+1):
  su[i][0] = 1
for j in range(1,m+1):
  su[0][j] = 1
  
for i in range(1,n+1):
  for j in range(1,m+1):
    if a[i] == b[j]:
      dp[i][j] = su[i-1][j-1]
    else:
      dp[i][j] = 0
    su[i][j] = su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j]
    su[i][j] %= mod
    
print(su[n][m]) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline n,m = map(int,readline().split()) n map(int,readline().split()) map int readline().split() ().split () readline split m mod = 10**9+7 mod 10**9+7 10**9 10 9 7 int(i) for i in readline().split() for i in readline().split() i readline().split() ().split () readline split for i in readline().split() int(i) int i a = [0]+[int(i) for i in readline().split()] a [0]+[int(i) for i in readline().split()] [0] 0 [int(i) for i in readline().split()] int(i) for i in readline().split() for i in readline().split() i readline().split() ().split () readline split for i in readline().split() int(i) int i b = [0]+[int(i) for i in readline().split()] b [0]+[int(i) for i in readline().split()] [0] 0 [int(i) for i in readline().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 dp = [[0]*(m+1) for i in range(n+1)] dp [[0]*(m+1) for i in range(n+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 su = [[0]*(m+1) for i in range(n+1)] su [[0]*(m+1) for i in range(n+1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 su[0][0] = 1 su[0][0] [0] su 0 0 1 for i in range(1,n+1):
  su[i][0] = 1 i range(1,n+1) range 1 n+1 n 1 su[i][0] = 1 su[i][0] [i] su i 0 1 for j in range(1,m+1):
  su[0][j] = 1
   j range(1,m+1) range 1 m+1 m 1 su[0][j] = 1 su[0][j] [0] su 0 j 1 for i in range(1,n+1):
  for j in range(1,m+1):
    if a[i] == b[j]:
      dp[i][j] = su[i-1][j-1]
    else:
      dp[i][j] = 0
    su[i][j] = su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j]
    su[i][j] %= mod
     i range(1,n+1) range 1 n+1 n 1 for j in range(1,m+1):
    if a[i] == b[j]:
      dp[i][j] = su[i-1][j-1]
    else:
      dp[i][j] = 0
    su[i][j] = su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j]
    su[i][j] %= mod
     j range(1,m+1) range 1 m+1 m 1 if a[i] == b[j]:
      dp[i][j] = su[i-1][j-1]
    else:
      dp[i][j] = 0
     a[i] == b[j] a[i] a i b[j] b j dp[i][j] = su[i-1][j-1] dp[i][j] [i] dp i j su[i-1][j-1] [i-1] su i-1 i 1 j-1 j 1 dp[i][j] = 0 dp[i][j] [i] dp i j 0 su[i][j] = su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j] su[i][j] [i] su i j su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j] su[i-1][j]+su[i][j-1]-su[i-1][j-1] su[i-1][j]+su[i][j-1] su[i-1][j] [i-1] su i-1 i 1 j su[i][j-1] [i] su i j-1 j 1 su[i-1][j-1] [i-1] su i-1 i 1 j-1 j 1 dp[i][j] [i] dp i j su[i][j] %= mod su[i][j] [i] su i j mod print(su[n][m]) print su[n][m] [n] su n m dp = [[0]*(m+1) for i in range(n+1)] [[0]*(m+1) for i in range(n+1)] dp su = [[0]*(m+1) for i in range(n+1)] [[0]*(m+1) for i in range(n+1)] su readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline read = sys.stdin.buffer.read sys.stdin.buffer.read read a = [0]+[int(i) for i in readline().split()] [0]+[int(i) for i in readline().split()] a n,m = map(int,readline().split()) map(int,readline().split()) n mod = 10**9+7 10**9+7 mod b = [0]+[int(i) for i in readline().split()] [0]+[int(i) for i in readline().split()] b m = map(int,readline().split()) map(int,readline().split()) m
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
mod = 10**9+7
a = [0]+[int(i) for i in readline().split()]
b = [0]+[int(i) for i in readline().split()]
dp = [[0]*(m+1) for i in range(n+1)]
su = [[0]*(m+1) for i in range(n+1)]

dp[0][0] = 1
su[0][0] = 1
for i in range(1,n+1):
  su[i][0] = 1
for j in range(1,m+1):
  su[0][j] = 1
  
for i in range(1,n+1):
  for j in range(1,m+1):
    if a[i] == b[j]:
      dp[i][j] = su[i-1][j-1]
    else:
      dp[i][j] = 0
    su[i][j] = su[i-1][j]+su[i][j-1]-su[i-1][j-1]+dp[i][j]
    su[i][j] %= mod
    
print(su[n][m])