def main():

    mod = 10**9 + 7

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

    S = list(map(int, input().split()))

    T = list(map(int, input().split()))

    u = [1] * (N + 1)

    v = [1] * (N + 1)

    for t in T:

        for i, s in enumerate(S, 1):

            if s == t:

                v[i] = v[i - 1] + u[i]

            else:

                v[i] = v[i - 1] + u[i] - u[i - 1]

        u, v = v, u

    return u[-1] % mod



print((main()))

def main():

    mod = 10**9 + 7

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

    S = list(map(int, input().split()))

    T = list(map(int, input().split()))

    V = [1] * N

    for t in T:

        p, q = 1, 1

        for i, (s, v) in enumerate(zip(S, V)):

            V[i] = q = v + q if s == t else v + q - p

            p = v

    return V[-1] % mod



print((main()))
def main():
    mod = 10**9 + 7
    N, M = list(map(int, input().split()))
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))
    u = [1] * (N + 1)
    v = [1] * (N + 1)
    for t in T:
        for i, s in enumerate(S, 1):
            if s == t:
                v[i] = v[i - 1] + u[i]
            else:
                v[i] = v[i - 1] + u[i] - u[i - 1]
        u, v = v, u
    return u[-1] % mod


print((main()))

def main():
    mod = 10**9 + 7
    N, M = list(map(int, input().split()))
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))
    V = [1] * N
    for t in T:
        p, q = 1, 1
        for i, (s, v) in enumerate(zip(S, V)):
            V[i] = q = v + q if s == t else v + q - p
            p = v
    return V[-1] % mod


print((main()))

-    u = [1] * (N + 1) -    v = [1] * (N + 1) +    V = [1] * N -        for i, s in enumerate(S, 1): -            if s == t: -                v[i] = v[i - 1] + u[i] -            else: -                v[i] = v[i - 1] + u[i] - u[i - 1] -        u, v = v, u -    return u[-1] % mod +        p, q = 1, 1 +        for i, (s, v) in enumerate(zip(S, V)): +            V[i] = q = v + q if s == t else v + q - p +            p = v +    return V[-1] % mod