import sys
mod=10**9+7
input=sys.stdin.buffer.readline
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[ [0 for _ in range(m)] for _ in range(n)]
for i in range(0,n):
    for j in range(0,m):
        ret=0
        if i-1>=0:
            ret+=dp[i-1][j]
        if j-1>=0:
            ret+=dp[i][j-1]
        if i-1>=0 and j-1>=0:
            ret-=dp[i-1][j-1]
        if s[i]==t[j]:
            ret+=1
            if i-1>=0 and j-1>=0:
                ret+=dp[i-1][j-1]
        if ret>=mod:
            ret%=mod
        if ret<0:
            ret+=mod
        dp[i][j]=ret
print((dp[n-1][m-1]+1))
 import sys sys mod=10**9+7 mod 10**9+7 10**9 10 9 7 input=sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline 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 [0 for _ in range(m)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0 for _ in range(m)] dp=[ [0 for _ in range(m)] for _ in range(n)] dp [ [0 for _ in range(m)] for _ in range(n)] for i in range(0,n):
    for j in range(0,m):
        ret=0
        if i-1>=0:
            ret+=dp[i-1][j]
        if j-1>=0:
            ret+=dp[i][j-1]
        if i-1>=0 and j-1>=0:
            ret-=dp[i-1][j-1]
        if s[i]==t[j]:
            ret+=1
            if i-1>=0 and j-1>=0:
                ret+=dp[i-1][j-1]
        if ret>=mod:
            ret%=mod
        if ret<0:
            ret+=mod
        dp[i][j]=ret i range(0,n) range 0 n for j in range(0,m):
        ret=0
        if i-1>=0:
            ret+=dp[i-1][j]
        if j-1>=0:
            ret+=dp[i][j-1]
        if i-1>=0 and j-1>=0:
            ret-=dp[i-1][j-1]
        if s[i]==t[j]:
            ret+=1
            if i-1>=0 and j-1>=0:
                ret+=dp[i-1][j-1]
        if ret>=mod:
            ret%=mod
        if ret<0:
            ret+=mod
        dp[i][j]=ret j range(0,m) range 0 m ret=0 ret 0 if i-1>=0:
            ret+=dp[i-1][j]
         i-1>=0 i-1 i 1 0 ret+=dp[i-1][j] ret dp[i-1][j] [i-1] dp i-1 i 1 j if j-1>=0:
            ret+=dp[i][j-1]
         j-1>=0 j-1 j 1 0 ret+=dp[i][j-1] ret dp[i][j-1] [i] dp i j-1 j 1 if i-1>=0 and j-1>=0:
            ret-=dp[i-1][j-1]
         i-1>=0 and j-1>=0 i-1>=0 i-1 i 1 0 j-1>=0 j-1 j 1 0 ret-=dp[i-1][j-1] ret dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 if s[i]==t[j]:
            ret+=1
            if i-1>=0 and j-1>=0:
                ret+=dp[i-1][j-1]
         s[i]==t[j] s[i] s i t[j] t j ret+=1 ret 1 if i-1>=0 and j-1>=0:
                ret+=dp[i-1][j-1]
         i-1>=0 and j-1>=0 i-1>=0 i-1 i 1 0 j-1>=0 j-1 j 1 0 ret+=dp[i-1][j-1] ret dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 if ret>=mod:
            ret%=mod
         ret>=mod ret mod ret%=mod ret mod if ret<0:
            ret+=mod
         ret<0 ret 0 ret+=mod ret mod dp[i][j]=ret dp[i][j] [i] dp i j ret print((dp[n-1][m-1]+1)) print dp[n-1][m-1]+1 dp[n-1][m-1] [n-1] dp n-1 n 1 m-1 m 1 1 mod=10**9+7 10**9+7 mod ret=0 0 ret ret-=dp[i-1][j-1] dp[i-1][j-1] ret ret+=dp[i-1][j] dp[i-1][j] ret ret+=dp[i-1][j-1] dp[i-1][j-1] ret input=sys.stdin.buffer.readline sys.stdin.buffer.readline input s=list(map(int,input().split())) list(map(int,input().split())) s ret+=dp[i][j-1] dp[i][j-1] ret ret+=1 1 ret ret%=mod mod ret m=map(int,input().split()) map(int,input().split()) m t=list(map(int,input().split())) list(map(int,input().split())) t ret+=mod mod ret dp=[ [0 for _ in range(m)] for _ in range(n)] [ [0 for _ in range(m)] for _ in range(n)] dp n,m=map(int,input().split()) map(int,input().split()) n
import sys
mod=10**9+7
input=sys.stdin.buffer.readline
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[ [0 for _ in range(m)] for _ in range(n)]
for i in range(0,n):
    for j in range(0,m):
        ret=0
        if i-1>=0:
            ret+=dp[i-1][j]
        if j-1>=0:
            ret+=dp[i][j-1]
        if i-1>=0 and j-1>=0:
            ret-=dp[i-1][j-1]
        if s[i]==t[j]:
            ret+=1
            if i-1>=0 and j-1>=0:
                ret+=dp[i-1][j-1]
        if ret>=mod:
            ret%=mod
        if ret<0:
            ret+=mod
        dp[i][j]=ret
print((dp[n-1][m-1]+1))

