

def resolve():
    MOD = int(1e9+7)
    N,M = map(int,input().split())
    S= list(map(int,input().split()))
    T= list(map(int,input().split()))
    dpt = [[0]*(M+1) for i in range(N+1)]

    sm = [[0]*(M+1) for i in range(N+1)]

    for i in range(N):
        for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
    ans =0
    for dptr in dpt:
        for i in dptr:
            ans += i
            ans %= MOD

    print(ans+1)            



if __name__ == "__main__":
    resolve() def resolve():
    MOD = int(1e9+7)
    N,M = map(int,input().split())
    S= list(map(int,input().split()))
    T= list(map(int,input().split()))
    dpt = [[0]*(M+1) for i in range(N+1)]

    sm = [[0]*(M+1) for i in range(N+1)]

    for i in range(N):
        for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
    ans =0
    for dptr in dpt:
        for i in dptr:
            ans += i
            ans %= MOD

    print(ans+1)             resolve MOD = int(1e9+7) MOD int(1e9+7) int 1e9+7 1e9 7 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]*(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 dpt = [[0]*(M+1) for i in range(N+1)] dpt [[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 sm = [[0]*(M+1) for i in range(N+1)] sm [[0]*(M+1) for i in range(N+1)] for i in range(N):
        for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
     i range(N) range N for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
     j range(M) range M dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0 dpt[i+1][j+1] [i+1] dpt i+1 i 1 j+1 j 1 sm[i][j]+1 if S[i]==T[j] else 0 S[i]==T[j] S[i] S i T[j] T j sm[i][j]+1 sm[i][j] [i] sm i j 1 0 sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD sm[i+1][j+1] [i+1] sm i+1 i 1 j+1 j 1 (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j] sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1] sm[i][j+1]+sm[i+1][j] sm[i][j+1] [i] sm i j+1 j 1 sm[i+1][j] [i+1] sm i+1 i 1 j dpt[i+1][j+1] [i+1] dpt i+1 i 1 j+1 j 1 sm[i][j] [i] sm i j MOD MOD ans =0 ans 0 for dptr in dpt:
        for i in dptr:
            ans += i
            ans %= MOD

     dptr dpt for i in dptr:
            ans += i
            ans %= MOD

     i dptr ans += i ans i ans %= MOD ans MOD print(ans+1) print ans+1 ans 1 if __name__ == "__main__":
    resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
    MOD = int(1e9+7)
    N,M = map(int,input().split())
    S= list(map(int,input().split()))
    T= list(map(int,input().split()))
    dpt = [[0]*(M+1) for i in range(N+1)]

    sm = [[0]*(M+1) for i in range(N+1)]

    for i in range(N):
        for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
    ans =0
    for dptr in dpt:
        for i in dptr:
            ans += i
            ans %= MOD

    print(ans+1)             def resolve():
    MOD = int(1e9+7)
    N,M = map(int,input().split())
    S= list(map(int,input().split()))
    T= list(map(int,input().split()))
    dpt = [[0]*(M+1) for i in range(N+1)]

    sm = [[0]*(M+1) for i in range(N+1)]

    for i in range(N):
        for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
    ans =0
    for dptr in dpt:
        for i in dptr:
            ans += i
            ans %= MOD

    print(ans+1)             resolve


def resolve():
    MOD = int(1e9+7)
    N,M = map(int,input().split())
    S= list(map(int,input().split()))
    T= list(map(int,input().split()))
    dpt = [[0]*(M+1) for i in range(N+1)]

    sm = [[0]*(M+1) for i in range(N+1)]

    for i in range(N):
        for j in range(M):
            dpt[i+1][j+1]= sm[i][j]+1 if S[i]==T[j] else 0

            sm[i+1][j+1] = (sm[i][j+1]+sm[i+1][j]+dpt[i+1][j+1]-sm[i][j]+MOD)%MOD
    ans =0
    for dptr in dpt:
        for i in dptr:
            ans += i
            ans %= MOD

    print(ans+1)            



if __name__ == "__main__":
    resolve()