def main():
    e=enumerate
    n,m,*u=map(int,open(0).read().split())
    dp=[[1]*(m+1)for _ in range(n+1)]
    dpi=dp[0]
    for i,s in e(u[:n]):
        dpi1=dp[i+1]
        for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
        dpi=dpi1
    print(dpi[m])
main() def main():
    e=enumerate
    n,m,*u=map(int,open(0).read().split())
    dp=[[1]*(m+1)for _ in range(n+1)]
    dpi=dp[0]
    for i,s in e(u[:n]):
        dpi1=dp[i+1]
        for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
        dpi=dpi1
    print(dpi[m]) main e=enumerate e enumerate n,m,*u=map(int,open(0).read().split()) n map(int,open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split m *u u [1]*(m+1)for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [1]*(m+1) [1] 1 m+1 m 1 dp=[[1]*(m+1)for _ in range(n+1)] dp [[1]*(m+1)for _ in range(n+1)] dpi=dp[0] dpi dp[0] dp 0 for i,s in e(u[:n]):
        dpi1=dp[i+1]
        for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
        dpi=dpi1
     i s e(u[:n]) e u[:n] u :n n dpi1=dp[i+1] dpi1 dp[i+1] dp i+1 i 1 for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
         j t e(u[n:]) e u[n:] u n: n dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7) dpi1[j+1] dpi1 j+1 j 1 (dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7) dpi[j+1]+dpi1[j]-dpi[j]*(s!=t) dpi[j+1]+dpi1[j] dpi[j+1] dpi j+1 j 1 dpi1[j] dpi1 j dpi[j]*(s!=t) dpi[j] dpi j s!=t s t 10**9+7 10**9 10 9 7 dpi=dpi1 dpi dpi1 print(dpi[m]) print dpi[m] dpi m main() main def main():
    e=enumerate
    n,m,*u=map(int,open(0).read().split())
    dp=[[1]*(m+1)for _ in range(n+1)]
    dpi=dp[0]
    for i,s in e(u[:n]):
        dpi1=dp[i+1]
        for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
        dpi=dpi1
    print(dpi[m]) def main():
    e=enumerate
    n,m,*u=map(int,open(0).read().split())
    dp=[[1]*(m+1)for _ in range(n+1)]
    dpi=dp[0]
    for i,s in e(u[:n]):
        dpi1=dp[i+1]
        for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
        dpi=dpi1
    print(dpi[m]) main
def main():
    e=enumerate
    n,m,*u=map(int,open(0).read().split())
    dp=[[1]*(m+1)for _ in range(n+1)]
    dpi=dp[0]
    for i,s in e(u[:n]):
        dpi1=dp[i+1]
        for j,t in e(u[n:]):
            dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
        dpi=dpi1
    print(dpi[m])
main()