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

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