mod=1e9+7
import sys
input=sys.stdin.readline

if __name__ == '__main__':
    N,M=list(map(int,input().split()))
    S=list(map(int,input().split()))
    T=list(map(int,input().split()))
    sum=[[0 for i in range(M+1)] for j in range(N+1)]
    dp=[[0 for i in range(M+1)] for j in range(N+1)]

    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]+=sum[i][j]+1
                dp[i+1][j+1]%=mod
            else:
                dp[i + 1][j + 1] =0

            sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1]
            sum[i + 1][j + 1]%=mod


    ans=sum[N][M]+1
    print(int(ans))
 mod=1e9+7 mod 1e9+7 1e9 7 import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline if __name__ == '__main__':
    N,M=list(map(int,input().split()))
    S=list(map(int,input().split()))
    T=list(map(int,input().split()))
    sum=[[0 for i in range(M+1)] for j in range(N+1)]
    dp=[[0 for i in range(M+1)] for j in range(N+1)]

    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]+=sum[i][j]+1
                dp[i+1][j+1]%=mod
            else:
                dp[i + 1][j + 1] =0

            sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1]
            sum[i + 1][j + 1]%=mod


    ans=sum[N][M]+1
    print(int(ans)) __name__ == '__main__' __name__ '__main__' N,M=list(map(int,input().split())) N list(map(int,input().split())) list 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 i in range(M+1)] for j in range(N+1) for j in range(N+1) j range(N+1) range N+1 N 1 for j in range(N+1) [0 for i in range(M+1)] sum=[[0 for i in range(M+1)] for j in range(N+1)] sum [[0 for i in range(M+1)] for j in range(N+1)] [0 for i in range(M+1)] for j in range(N+1) for j in range(N+1) j range(N+1) range N+1 N 1 for j in range(N+1) [0 for i in range(M+1)] dp=[[0 for i in range(M+1)] for j in range(N+1)] dp [[0 for i in range(M+1)] for j in range(N+1)] for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]+=sum[i][j]+1
                dp[i+1][j+1]%=mod
            else:
                dp[i + 1][j + 1] =0

            sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1]
            sum[i + 1][j + 1]%=mod


     i range(N) range N for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]+=sum[i][j]+1
                dp[i+1][j+1]%=mod
            else:
                dp[i + 1][j + 1] =0

            sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1]
            sum[i + 1][j + 1]%=mod


     j range(M) range M if S[i]==T[j]:
                dp[i+1][j+1]+=sum[i][j]+1
                dp[i+1][j+1]%=mod
            else:
                dp[i + 1][j + 1] =0

             S[i]==T[j] S[i] S i T[j] T j dp[i+1][j+1]+=sum[i][j]+1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sum[i][j]+1 sum[i][j] [i] sum i j 1 dp[i+1][j+1]%=mod dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 mod dp[i + 1][j + 1] =0 dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 0 sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1] sum[i+1][j+1] [i+1] sum i+1 i 1 j+1 j 1 sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1] sum[i][j+1]+sum[i+1][j]-sum[i][j] sum[i][j+1]+sum[i+1][j] sum[i][j+1] [i] sum i j+1 j 1 sum[i+1][j] [i+1] sum i+1 i 1 j sum[i][j] [i] sum i j dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sum[i + 1][j + 1]%=mod sum[i + 1][j + 1] [i + 1] sum i + 1 i 1 j + 1 j 1 mod ans=sum[N][M]+1 ans sum[N][M]+1 sum[N][M] [N] sum N M 1 print(int(ans)) print int(ans) int ans N,M=list(map(int,input().split())) list(map(int,input().split())) N mod=1e9+7 1e9+7 mod ans=sum[N][M]+1 sum[N][M]+1 ans S=list(map(int,input().split())) list(map(int,input().split())) S dp=[[0 for i in range(M+1)] for j in range(N+1)] [[0 for i in range(M+1)] for j in range(N+1)] dp T=list(map(int,input().split())) list(map(int,input().split())) T input=sys.stdin.readline sys.stdin.readline input M=list(map(int,input().split())) list(map(int,input().split())) M sum=[[0 for i in range(M+1)] for j in range(N+1)] [[0 for i in range(M+1)] for j in range(N+1)] sum
mod=1e9+7
import sys
input=sys.stdin.readline

if __name__ == '__main__':
    N,M=list(map(int,input().split()))
    S=list(map(int,input().split()))
    T=list(map(int,input().split()))
    sum=[[0 for i in range(M+1)] for j in range(N+1)]
    dp=[[0 for i in range(M+1)] for j in range(N+1)]

    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]+=sum[i][j]+1
                dp[i+1][j+1]%=mod
            else:
                dp[i + 1][j + 1] =0

            sum[i+1][j+1]=sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1]
            sum[i + 1][j + 1]%=mod


    ans=sum[N][M]+1
    print(int(ans))

