import math


class Solution:
    def solve(self, N: int, M: int, S, T):

        mod = 10**9 + 7

        N_MAX = 2005

        dp = [[0] * N_MAX for _ in range(N_MAX)]
        s = [[0] * N_MAX for _ in range(N_MAX)]

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

        return (s[N][M] + 1)


if __name__ == '__main__':

    # standard input
    N, M = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    # solve
    solution = Solution()
    print(solution.solve(N, M, S, T)) import math math class Solution:
    def solve(self, N: int, M: int, S, T):

        mod = 10**9 + 7

        N_MAX = 2005

        dp = [[0] * N_MAX for _ in range(N_MAX)]
        s = [[0] * N_MAX for _ in range(N_MAX)]

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

        return (s[N][M] + 1) Solution def solve(self, N: int, M: int, S, T):

        mod = 10**9 + 7

        N_MAX = 2005

        dp = [[0] * N_MAX for _ in range(N_MAX)]
        s = [[0] * N_MAX for _ in range(N_MAX)]

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

        return (s[N][M] + 1) solve mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 N_MAX = 2005 N_MAX 2005 [0] * N_MAX for _ in range(N_MAX) for _ in range(N_MAX) _ range(N_MAX) range N_MAX for _ in range(N_MAX) [0] * N_MAX [0] 0 N_MAX dp = [[0] * N_MAX for _ in range(N_MAX)] dp [[0] * N_MAX for _ in range(N_MAX)] [0] * N_MAX for _ in range(N_MAX) for _ in range(N_MAX) _ range(N_MAX) range N_MAX for _ in range(N_MAX) [0] * N_MAX [0] 0 N_MAX s = [[0] * N_MAX for _ in range(N_MAX)] s [[0] * N_MAX for _ in range(N_MAX)] for i in range(1, N + 1):
            for j in range(1, M + 1):
                dp = 0
                if S[i - 1] == T[j - 1]:
                    dp = s[i - 1][j - 1] + 1
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + dp
                s[i][j] %= mod

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

         j range(1, M + 1) range 1 M + 1 M 1 dp = 0 dp 0 if S[i - 1] == T[j - 1]:
                    dp = s[i - 1][j - 1] + 1
                 S[i - 1] == T[j - 1] S[i - 1] S i - 1 i 1 T[j - 1] T j - 1 j 1 dp = s[i - 1][j - 1] + 1 dp s[i - 1][j - 1] + 1 s[i - 1][j - 1] [i - 1] s i - 1 i 1 j - 1 j 1 1 s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + dp s[i][j] [i] s i j s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + dp s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] s[i - 1][j] + s[i][j - 1] s[i - 1][j] [i - 1] s i - 1 i 1 j s[i][j - 1] [i] s i j - 1 j 1 s[i - 1][j - 1] [i - 1] s i - 1 i 1 j - 1 j 1 dp s[i][j] %= mod s[i][j] [i] s i j mod return (s[N][M] + 1) s[N][M] + 1 s[N][M] [N] s N M 1 self self N: int N M: int M S S T T if __name__ == '__main__':

    # standard input
    N, M = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    # solve
    solution = Solution()
    print(solution.solve(N, M, S, T)) __name__ == '__main__' __name__ '__main__' 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 solution = Solution() solution Solution() Solution print(solution.solve(N, M, S, T)) print solution.solve(N, M, S, T) solution.solve solution solve N M S T M = map(int, input().split()) map(int, input().split()) M T = list(map(int, input().split())) list(map(int, input().split())) T class Solution:
    def solve(self, N: int, M: int, S, T):

        mod = 10**9 + 7

        N_MAX = 2005

        dp = [[0] * N_MAX for _ in range(N_MAX)]
        s = [[0] * N_MAX for _ in range(N_MAX)]

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

        return (s[N][M] + 1) class Solution:
    def solve(self, N: int, M: int, S, T):

        mod = 10**9 + 7

        N_MAX = 2005

        dp = [[0] * N_MAX for _ in range(N_MAX)]
        s = [[0] * N_MAX for _ in range(N_MAX)]

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

        return (s[N][M] + 1) Solution N, M = map(int, input().split()) map(int, input().split()) N solution = Solution() Solution() solution S = list(map(int, input().split())) list(map(int, input().split())) S
import math


class Solution:
    def solve(self, N: int, M: int, S, T):

        mod = 10**9 + 7

        N_MAX = 2005

        dp = [[0] * N_MAX for _ in range(N_MAX)]
        s = [[0] * N_MAX for _ in range(N_MAX)]

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

        return (s[N][M] + 1)


if __name__ == '__main__':

    # standard input
    N, M = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    # solve
    solution = Solution()
    print(solution.solve(N, M, S, T))
