ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq

n,m = ma()
s = ips()
t = ips()
dp = [[0]*(m+1) for i in range(n+1) ] # dp[i][j]は s[i],t[j]まで見た時初めて一致する整数列の個数 0idx
tot = [[0]*(m+1) for i in range(n+1) ] #tot[n][m] n,mまで見た時に一致するもの全部, sum dp[0:i+1][0:j+1]
mod=10**9+7
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i][j]=tot[i-1][j-1]+1
        else:
            dp[i][j]=0
        tot[i][j] = (dp[i][j] + tot[i][j-1]+tot[i-1][j] -tot[i-1][j-1])%mod

print((tot[n-1][m-1]+1)%mod)
#print(tot)
#print(dp) ma = lambda :map(int,input().split()) ma lambda :map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split lma = lambda :list(map(int,input().split())) lma lambda :list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split tma = lambda :tuple(map(int,input().split())) tma lambda :tuple(map(int,input().split())) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split ni = lambda:int(input()) ni lambda:int(input()) int(input()) int input() input yn = lambda fl:print("Yes") if fl else print("No") yn lambda fl:print("Yes") if fl else print("No") print("Yes") if fl else print("No") fl print("Yes") print "Yes" print("No") print "No" fl ips = lambda:input().split() ips lambda:input().split() input().split() ().split () input split import collections collections import math math import itertools itertools import heapq as hq heapq n,m = ma() n ma() ma m s = ips() s ips() ips t = ips() t ips() ips [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 tot = [[0]*(m+1) for i in range(n+1) ] tot [[0]*(m+1) for i in range(n+1) ] mod=10**9+7 mod 10**9+7 10**9 10 9 7 for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i][j]=tot[i-1][j-1]+1
        else:
            dp[i][j]=0
        tot[i][j] = (dp[i][j] + tot[i][j-1]+tot[i-1][j] -tot[i-1][j-1])%mod i range(n) range n for j in range(m):
        if s[i]==t[j]:
            dp[i][j]=tot[i-1][j-1]+1
        else:
            dp[i][j]=0
        tot[i][j] = (dp[i][j] + tot[i][j-1]+tot[i-1][j] -tot[i-1][j-1])%mod j range(m) range m if s[i]==t[j]:
            dp[i][j]=tot[i-1][j-1]+1
        else:
            dp[i][j]=0
         s[i]==t[j] s[i] s i t[j] t j dp[i][j]=tot[i-1][j-1]+1 dp[i][j] [i] dp i j tot[i-1][j-1]+1 tot[i-1][j-1] [i-1] tot i-1 i 1 j-1 j 1 1 dp[i][j]=0 dp[i][j] [i] dp i j 0 tot[i][j] = (dp[i][j] + tot[i][j-1]+tot[i-1][j] -tot[i-1][j-1])%mod tot[i][j] [i] tot i j (dp[i][j] + tot[i][j-1]+tot[i-1][j] -tot[i-1][j-1])%mod dp[i][j] + tot[i][j-1]+tot[i-1][j] -tot[i-1][j-1] dp[i][j] + tot[i][j-1]+tot[i-1][j] dp[i][j] + tot[i][j-1] dp[i][j] [i] dp i j tot[i][j-1] [i] tot i j-1 j 1 tot[i-1][j] [i-1] tot i-1 i 1 j tot[i-1][j-1] [i-1] tot i-1 i 1 j-1 j 1 mod print((tot[n-1][m-1]+1)%mod) print (tot[n-1][m-1]+1)%mod tot[n-1][m-1]+1 tot[n-1][m-1] [n-1] tot n-1 n 1 m-1 m 1 1 mod n,m = ma() ma() n dp = [[0]*(m+1) for i in range(n+1) ] [[0]*(m+1) for i in range(n+1) ] dp s = ips() ips() s ips = lambda:input().split() lambda:input().split() ips m = ma() ma() m lma = lambda :list(map(int,input().split())) lambda :list(map(int,input().split())) lma tma = lambda :tuple(map(int,input().split())) lambda :tuple(map(int,input().split())) tma t = ips() ips() t tot = [[0]*(m+1) for i in range(n+1) ] [[0]*(m+1) for i in range(n+1) ] tot yn = lambda fl:print("Yes") if fl else print("No") lambda fl:print("Yes") if fl else print("No") yn ma = lambda :map(int,input().split()) lambda :map(int,input().split()) ma mod=10**9+7 10**9+7 mod ni = lambda:int(input()) lambda:int(input()) ni
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq

n,m = ma()
s = ips()
t = ips()
dp = [[0]*(m+1) for i in range(n+1) ] # dp[i][j]は s[i],t[j]まで見た時初めて一致する整数列の個数 0idx
tot = [[0]*(m+1) for i in range(n+1) ] #tot[n][m] n,mまで見た時に一致するもの全部, sum dp[0:i+1][0:j+1]
mod=10**9+7
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i][j]=tot[i-1][j-1]+1
        else:
            dp[i][j]=0
        tot[i][j] = (dp[i][j] + tot[i][j-1]+tot[i-1][j] -tot[i-1][j-1])%mod

print((tot[n-1][m-1]+1)%mod)
#print(tot)
#print(dp)
