N, M = map(int, input().split())
*S, = map(int, input().split())
*T, = map(int, input().split())

data = [0]*(M+2)
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s % MOD
def add(k, x):
    while k <= M:
        data[k] = (data[k] + x) % MOD
        k += k & -k

MOD = 10**9 + 7
s = 0
rM = range(M-1, -1, -1)
for i in range(N):
    si = S[i]
    for j in rM:
        if si == T[j]:
            v = get(j+1) + 1
            add(j+2, v); s += v
print((s + 1) % MOD) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M *S, = map(int, input().split()) *S S map(int, input().split()) map int input().split() ().split () input split *T, = map(int, input().split()) *T T map(int, input().split()) map int input().split() ().split () input split data = [0]*(M+2) data [0]*(M+2) [0] 0 M+2 M 2 def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s % MOD get s = 0 s 0 while k:
        s += data[k]
        k -= k & -k
     k s += data[k] s data[k] data k k -= k & -k k k & -k k -k k return s % MOD s % MOD s MOD k k def add(k, x):
    while k <= M:
        data[k] = (data[k] + x) % MOD
        k += k & -k add while k <= M:
        data[k] = (data[k] + x) % MOD
        k += k & -k k <= M k M data[k] = (data[k] + x) % MOD data[k] data k (data[k] + x) % MOD data[k] + x data[k] data k x MOD k += k & -k k k & -k k -k k k k x x MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 s = 0 s 0 rM = range(M-1, -1, -1) rM range(M-1, -1, -1) range M-1 M 1 -1 -1 for i in range(N):
    si = S[i]
    for j in rM:
        if si == T[j]:
            v = get(j+1) + 1
            add(j+2, v); s += v i range(N) range N si = S[i] si S[i] S i for j in rM:
        if si == T[j]:
            v = get(j+1) + 1
            add(j+2, v); s += v j rM if si == T[j]:
            v = get(j+1) + 1
            add(j+2, v); s += v si == T[j] si T[j] T j v = get(j+1) + 1 v get(j+1) + 1 get(j+1) get j+1 j 1 1 add(j+2, v) add j+2 j 2 v s += v s v print((s + 1) % MOD) print (s + 1) % MOD s + 1 s 1 MOD data = [0]*(M+2) [0]*(M+2) data si = S[i] S[i] si v = get(j+1) + 1 get(j+1) + 1 v s += v v s N, M = map(int, input().split()) map(int, input().split()) N def add(k, x):
    while k <= M:
        data[k] = (data[k] + x) % MOD
        k += k & -k def add(k, x):
    while k <= M:
        data[k] = (data[k] + x) % MOD
        k += k & -k add s = 0 0 s M = map(int, input().split()) map(int, input().split()) M rM = range(M-1, -1, -1) range(M-1, -1, -1) rM def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s % MOD def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s % MOD get MOD = 10**9 + 7 10**9 + 7 MOD
N, M = map(int, input().split())
*S, = map(int, input().split())
*T, = map(int, input().split())

data = [0]*(M+2)
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s % MOD
def add(k, x):
    while k <= M:
        data[k] = (data[k] + x) % MOD
        k += k & -k

MOD = 10**9 + 7
s = 0
rM = range(M-1, -1, -1)
for i in range(N):
    si = S[i]
    for j in rM:
        if si == T[j]:
            v = get(j+1) + 1
            add(j+2, v); s += v
print((s + 1) % MOD)