# coding: utf-8
import sys
input = sys.stdin.readline

MOD = int(1e9 + 7)

def f(N, M, s, t):
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
    return((cums[N][M] + 1) % MOD)

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(f(n, m, s, t)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MOD = int(1e9 + 7) MOD int(1e9 + 7) int 1e9 + 7 1e9 7 def f(N, M, s, t):
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
    return((cums[N][M] + 1) % MOD) f [0] * (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] * (M + 1) [0] 0 M + 1 M 1 cums = [[0] * (M + 1) for _ in range(N + 1)] cums [[0] * (M + 1) for _ in range(N + 1)] for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
     i range(N) range N cumsi = cums[i] cumsi cums[i] cums i cumsi1 = cums[i+1] cumsi1 cums[i+1] cums i+1 i 1 for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
     j range(M) range M num = 0 num 0 if s[i] == t[j]:
                num = cumsi[j] + 1
             s[i] == t[j] s[i] s i t[j] t j num = cumsi[j] + 1 num cumsi[j] + 1 cumsi[j] cumsi j 1 cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD cumsi1[j+1] cumsi1 j+1 j 1 (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD cumsi1[j] + cumsi[j+1] - cumsi[j] + num cumsi1[j] + cumsi[j+1] - cumsi[j] cumsi1[j] + cumsi[j+1] cumsi1[j] cumsi1 j cumsi[j+1] cumsi j+1 j 1 cumsi[j] cumsi j num MOD return((cums[N][M] + 1) % MOD) (cums[N][M] + 1) % MOD cums[N][M] + 1 cums[N][M] [N] cums N M 1 MOD N N M M s s t t 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 print(f(n, m, s, t)) print f(n, m, s, t) f n m s t n, m = map(int, input().split()) map(int, input().split()) n def f(N, M, s, t):
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
    return((cums[N][M] + 1) % MOD) def f(N, M, s, t):
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
    return((cums[N][M] + 1) % MOD) f t = list(map(int, input().split())) list(map(int, input().split())) t m = map(int, input().split()) map(int, input().split()) m s = list(map(int, input().split())) list(map(int, input().split())) s input = sys.stdin.readline sys.stdin.readline input MOD = int(1e9 + 7) int(1e9 + 7) MOD
# coding: utf-8
import sys
input = sys.stdin.readline

MOD = int(1e9 + 7)

def f(N, M, s, t):
    cums = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        cumsi = cums[i]
        cumsi1 = cums[i+1]
        for j in range(M):
            num = 0
            if s[i] == t[j]:
                num = cumsi[j] + 1
            cumsi1[j+1] = \
                (cumsi1[j] + cumsi[j+1] - cumsi[j] + num) % MOD
    return((cums[N][M] + 1) % MOD)

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(f(n, m, s, t))
