import sys

def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N, M = map(int, input().split())
    S = [int(s) for s in input().split()]
    T = [int(t) for t in input().split()]

    DP = [[0 for j in range(M+1)] for i in range(N + 1)]
    DP[0] = [1] * (M + 1)
    for i in range(1, N + 1): DP[i][0] = 1
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
    print(DP[N][M])
    return

if __name__ == "__main__":
    solve() import sys sys def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N, M = map(int, input().split())
    S = [int(s) for s in input().split()]
    T = [int(t) for t in input().split()]

    DP = [[0 for j in range(M+1)] for i in range(N + 1)]
    DP[0] = [1] * (M + 1)
    for i in range(1, N + 1): DP[i][0] = 1
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
    print(DP[N][M])
    return solve input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline mod = 7 + 10 ** 9 mod 7 + 10 ** 9 7 10 ** 9 10 9 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s S = [int(s) for s in input().split()] S [int(s) for s in input().split()] int(t) for t in input().split() for t in input().split() t input().split() ().split () input split for t in input().split() int(t) int t T = [int(t) for t in input().split()] T [int(t) for t in input().split()] [0 for j in range(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 for j in range(M+1)] DP = [[0 for j in range(M+1)] for i in range(N + 1)] DP [[0 for j in range(M+1)] for i in range(N + 1)] DP[0] = [1] * (M + 1) DP[0] DP 0 [1] * (M + 1) [1] 1 M + 1 M 1 for i in range(1, N + 1): DP[i][0] = 1
     i range(1, N + 1) range 1 N + 1 N 1 for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
     i range(N) range N for j in range(M):
            if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
     j range(M) range M if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
     S[i] == T[j] S[i] S i T[j] T j DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod DP[i+1][j+1] [i+1] DP i+1 i 1 j+1 j 1 (DP[i+1][j] + DP[i][j+1]) % mod DP[i+1][j] + DP[i][j+1] DP[i+1][j] [i+1] DP i+1 i 1 j DP[i][j+1] [i] DP i j+1 j 1 mod DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod DP[i+1][j+1] [i+1] DP i+1 i 1 j+1 j 1 (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod DP[i+1][j] + DP[i][j+1] - DP[i][j] DP[i+1][j] + DP[i][j+1] DP[i+1][j] [i+1] DP i+1 i 1 j DP[i][j+1] [i] DP i j+1 j 1 DP[i][j] [i] DP i j mod print(DP[N][M]) print DP[N][M] [N] DP N M return if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N, M = map(int, input().split())
    S = [int(s) for s in input().split()]
    T = [int(t) for t in input().split()]

    DP = [[0 for j in range(M+1)] for i in range(N + 1)]
    DP[0] = [1] * (M + 1)
    for i in range(1, N + 1): DP[i][0] = 1
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
    print(DP[N][M])
    return def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N, M = map(int, input().split())
    S = [int(s) for s in input().split()]
    T = [int(t) for t in input().split()]

    DP = [[0 for j in range(M+1)] for i in range(N + 1)]
    DP[0] = [1] * (M + 1)
    for i in range(1, N + 1): DP[i][0] = 1
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
    print(DP[N][M])
    return solve
import sys

def solve():
    input = sys.stdin.readline
    mod = 7 + 10 ** 9
    N, M = map(int, input().split())
    S = [int(s) for s in input().split()]
    T = [int(t) for t in input().split()]

    DP = [[0 for j in range(M+1)] for i in range(N + 1)]
    DP[0] = [1] * (M + 1)
    for i in range(1, N + 1): DP[i][0] = 1
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1]) % mod
            else: 
                DP[i+1][j+1] = (DP[i+1][j] + DP[i][j+1] - DP[i][j]) % mod
    print(DP[N][M])
    return

if __name__ == "__main__":
    solve()