def f(n, m):
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m) def f(n, m):
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1]) f 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 [1] * (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) [1] * (m + 1) [1] 1 m + 1 m 1 dp = [[1] * (m + 1) for _ in range(n + 1)] dp [[1] * (m + 1) for _ in range(n + 1)] for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
     i sk enumerate(s) enumerate s dpi1 = dp[i + 1] = dp[i][:] dpi1 dp[i][:] [i] dp i : = dp[i + 1] = dp[i][:] dp[i + 1] dp i + 1 i 1 dp[i][:] cs = 0 cs 0 for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
     j tk enumerate(t) enumerate t if sk == tk:
                cs = (cs + dp[i][j]) % md
             sk == tk sk tk cs = (cs + dp[i][j]) % md cs (cs + dp[i][j]) % md cs + dp[i][j] cs dp[i][j] [i] dp i j md dpi1[j + 1] = (dpi1[j + 1] + cs) % md dpi1[j + 1] dpi1 j + 1 j 1 (dpi1[j + 1] + cs) % md dpi1[j + 1] + cs dpi1[j + 1] dpi1 j + 1 j 1 cs md print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 n n m m md = 10 ** 9 + 7 md 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 f(n, m) f n m n, m = map(int, input().split()) map(int, input().split()) n def f(n, m):
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1]) def f(n, m):
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1]) f m = map(int, input().split()) map(int, input().split()) m md = 10 ** 9 + 7 10 ** 9 + 7 md
def f(n, m):
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m)
