def solve():
    MOD = 10**9 + 7

    N, M = map(int, input().split())
    Ss = list(map(int, input().split()))
    Ts = list(map(int, input().split()))

    dp = [1]*(M+1)
    for i, S in enumerate(Ss, 1):
        dp2 = [1]*(M+1)
        for j, T in enumerate(Ts, 1):
            dp2[j] = dp[j] + dp2[j-1]
            if S != T:
                dp2[j] -= dp[j-1]
            dp2[j] %= MOD
        dp = dp2

    print(dp[-1])


solve() def solve():
    MOD = 10**9 + 7

    N, M = map(int, input().split())
    Ss = list(map(int, input().split()))
    Ts = list(map(int, input().split()))

    dp = [1]*(M+1)
    for i, S in enumerate(Ss, 1):
        dp2 = [1]*(M+1)
        for j, T in enumerate(Ts, 1):
            dp2[j] = dp[j] + dp2[j-1]
            if S != T:
                dp2[j] -= dp[j-1]
            dp2[j] %= MOD
        dp = dp2

    print(dp[-1]) solve MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M Ss = list(map(int, input().split())) Ss list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Ts = list(map(int, input().split())) Ts list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = [1]*(M+1) dp [1]*(M+1) [1] 1 M+1 M 1 for i, S in enumerate(Ss, 1):
        dp2 = [1]*(M+1)
        for j, T in enumerate(Ts, 1):
            dp2[j] = dp[j] + dp2[j-1]
            if S != T:
                dp2[j] -= dp[j-1]
            dp2[j] %= MOD
        dp = dp2

     i S enumerate(Ss, 1) enumerate Ss 1 dp2 = [1]*(M+1) dp2 [1]*(M+1) [1] 1 M+1 M 1 for j, T in enumerate(Ts, 1):
            dp2[j] = dp[j] + dp2[j-1]
            if S != T:
                dp2[j] -= dp[j-1]
            dp2[j] %= MOD
         j T enumerate(Ts, 1) enumerate Ts 1 dp2[j] = dp[j] + dp2[j-1] dp2[j] dp2 j dp[j] + dp2[j-1] dp[j] dp j dp2[j-1] dp2 j-1 j 1 if S != T:
                dp2[j] -= dp[j-1]
             S != T S T dp2[j] -= dp[j-1] dp2[j] dp2 j dp[j-1] dp j-1 j 1 dp2[j] %= MOD dp2[j] dp2 j MOD dp = dp2 dp dp2 print(dp[-1]) print dp[-1] dp -1 solve() solve def solve():
    MOD = 10**9 + 7

    N, M = map(int, input().split())
    Ss = list(map(int, input().split()))
    Ts = list(map(int, input().split()))

    dp = [1]*(M+1)
    for i, S in enumerate(Ss, 1):
        dp2 = [1]*(M+1)
        for j, T in enumerate(Ts, 1):
            dp2[j] = dp[j] + dp2[j-1]
            if S != T:
                dp2[j] -= dp[j-1]
            dp2[j] %= MOD
        dp = dp2

    print(dp[-1]) def solve():
    MOD = 10**9 + 7

    N, M = map(int, input().split())
    Ss = list(map(int, input().split()))
    Ts = list(map(int, input().split()))

    dp = [1]*(M+1)
    for i, S in enumerate(Ss, 1):
        dp2 = [1]*(M+1)
        for j, T in enumerate(Ts, 1):
            dp2[j] = dp[j] + dp2[j-1]
            if S != T:
                dp2[j] -= dp[j-1]
            dp2[j] %= MOD
        dp = dp2

    print(dp[-1]) solve
def solve():
    MOD = 10**9 + 7

    N, M = map(int, input().split())
    Ss = list(map(int, input().split()))
    Ts = list(map(int, input().split()))

    dp = [1]*(M+1)
    for i, S in enumerate(Ss, 1):
        dp2 = [1]*(M+1)
        for j, T in enumerate(Ts, 1):
            dp2[j] = dp[j] + dp2[j-1]
            if S != T:
                dp2[j] -= dp[j-1]
            dp2[j] %= MOD
        dp = dp2

    print(dp[-1])


solve()
