import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, M = read_ints()
    S = read_ints()
    T = read_ints()
    dp = [
        [0 for _ in range(M+1)] for _ in range(N+1)
    ]
    dp[0][0] = 1
    for i in range(1, N+1):
        dp[i][0] = 1
    for j in range(1, M+1):
        dp[0][j] = 1
    modulo = 10**9+7
    for i in range(1, N+1):
        for j in range(1, M+1):
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo
            if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
    return dp[N][M]


if __name__ == '__main__':
    print(solve()) import math math from typing import List, Any def read_int() -> int:
    return int(input().strip()) read_int return int(input().strip()) int(input().strip()) int input().strip() ().strip () input strip def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' '))) read_ints return list(map(int, input().strip().split(' '))) list(map(int, input().strip().split(' '))) list map(int, input().strip().split(' ')) map int input().strip().split(' ') ().strip().split ().strip() ().strip () input strip split ' ' def solve() -> Any:
    N, M = read_ints()
    S = read_ints()
    T = read_ints()
    dp = [
        [0 for _ in range(M+1)] for _ in range(N+1)
    ]
    dp[0][0] = 1
    for i in range(1, N+1):
        dp[i][0] = 1
    for j in range(1, M+1):
        dp[0][j] = 1
    modulo = 10**9+7
    for i in range(1, N+1):
        for j in range(1, M+1):
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo
            if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
    return dp[N][M] solve N, M = read_ints() N read_ints() read_ints M S = read_ints() S read_ints() read_ints T = read_ints() T read_ints() read_ints [0 for _ in range(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) [0 for _ in range(M+1)] dp = [
        [0 for _ in range(M+1)] for _ in range(N+1)
    ] dp [
        [0 for _ in range(M+1)] for _ in range(N+1)
    ] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for i in range(1, N+1):
        dp[i][0] = 1
     i range(1, N+1) range 1 N+1 N 1 dp[i][0] = 1 dp[i][0] [i] dp i 0 1 for j in range(1, M+1):
        dp[0][j] = 1
     j range(1, M+1) range 1 M+1 M 1 dp[0][j] = 1 dp[0][j] [0] dp 0 j 1 modulo = 10**9+7 modulo 10**9+7 10**9 10 9 7 for i in range(1, N+1):
        for j in range(1, M+1):
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo
            if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
     i range(1, N+1) range 1 N+1 N 1 for j in range(1, M+1):
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo
            if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
     j range(1, M+1) range 1 M+1 M 1 dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo dp[i][j] [i] dp i j (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1] 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-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 modulo if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
     S[i-1] == T[j-1] S[i-1] S i-1 i 1 T[j-1] T j-1 j 1 dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo dp[i][j] [i] dp i j (dp[i][j]+dp[i-1][j-1])%modulo dp[i][j]+dp[i-1][j-1] dp[i][j] [i] dp i j dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 modulo return dp[N][M] dp[N][M] [N] dp N M if __name__ == '__main__':
    print(solve()) __name__ == '__main__' __name__ '__main__' print(solve()) print solve() solve def read_int() -> int:
    return int(input().strip()) def read_int() -> int:
    return int(input().strip()) read_int def solve() -> Any:
    N, M = read_ints()
    S = read_ints()
    T = read_ints()
    dp = [
        [0 for _ in range(M+1)] for _ in range(N+1)
    ]
    dp[0][0] = 1
    for i in range(1, N+1):
        dp[i][0] = 1
    for j in range(1, M+1):
        dp[0][j] = 1
    modulo = 10**9+7
    for i in range(1, N+1):
        for j in range(1, M+1):
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo
            if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
    return dp[N][M] def solve() -> Any:
    N, M = read_ints()
    S = read_ints()
    T = read_ints()
    dp = [
        [0 for _ in range(M+1)] for _ in range(N+1)
    ]
    dp[0][0] = 1
    for i in range(1, N+1):
        dp[i][0] = 1
    for j in range(1, M+1):
        dp[0][j] = 1
    modulo = 10**9+7
    for i in range(1, N+1):
        for j in range(1, M+1):
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo
            if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
    return dp[N][M] solve def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' '))) def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' '))) read_ints
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, M = read_ints()
    S = read_ints()
    T = read_ints()
    dp = [
        [0 for _ in range(M+1)] for _ in range(N+1)
    ]
    dp[0][0] = 1
    for i in range(1, N+1):
        dp[i][0] = 1
    for j in range(1, M+1):
        dp[0][j] = 1
    modulo = 10**9+7
    for i in range(1, N+1):
        for j in range(1, M+1):
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%modulo
            if S[i-1] == T[j-1]:
                dp[i][j] = (dp[i][j]+dp[i-1][j-1])%modulo
    return dp[N][M]


if __name__ == '__main__':
    print(solve())
