import copy
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp = [0 for i in range(max(n,m))]
mod = 10**9+7
if n > m:
    a = s
    b = t
else:
    a = t
    b = s
    c = copy.copy(n)
    n = copy.copy(m)
    m = copy.copy(c)
l = []
for i in range(m):
    now = b[i]
    bl = []
    for j in range(n):
        if now == a[j]:
            bl.append(j)
    l.append(bl)
for i in range(m):
    if len(l[i]) > 0:
        dp2 = copy.copy(dp)
        now1 = 0
        k = 0
        k1 = len(l[i])
        count = 0
        while k < k1:
            if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
            count += dp2[now1]
            count %= mod
            now1 += 1
        #print(dp)
print((sum(dp)+1)%mod) import copy copy 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 0 for i in range(max(n,m)) for i in range(max(n,m)) i range(max(n,m)) range max(n,m) max n m for i in range(max(n,m)) 0 dp = [0 for i in range(max(n,m))] dp [0 for i in range(max(n,m))] mod = 10**9+7 mod 10**9+7 10**9 10 9 7 if n > m:
    a = s
    b = t
else:
    a = t
    b = s
    c = copy.copy(n)
    n = copy.copy(m)
    m = copy.copy(c) n > m n m a = s a s b = t b t a = t a t b = s b s c = copy.copy(n) c copy.copy(n) copy.copy copy copy n n = copy.copy(m) n copy.copy(m) copy.copy copy copy m m = copy.copy(c) m copy.copy(c) copy.copy copy copy c l = [] l [] for i in range(m):
    now = b[i]
    bl = []
    for j in range(n):
        if now == a[j]:
            bl.append(j)
    l.append(bl) i range(m) range m now = b[i] now b[i] b i bl = [] bl [] for j in range(n):
        if now == a[j]:
            bl.append(j)
     j range(n) range n if now == a[j]:
            bl.append(j)
     now == a[j] now a[j] a j bl.append(j) bl.append bl append j l.append(bl) l.append l append bl for i in range(m):
    if len(l[i]) > 0:
        dp2 = copy.copy(dp)
        now1 = 0
        k = 0
        k1 = len(l[i])
        count = 0
        while k < k1:
            if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
            count += dp2[now1]
            count %= mod
            now1 += 1
        #print(dp) i range(m) range m if len(l[i]) > 0:
        dp2 = copy.copy(dp)
        now1 = 0
        k = 0
        k1 = len(l[i])
        count = 0
        while k < k1:
            if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
            count += dp2[now1]
            count %= mod
            now1 += 1
        #print(dp) len(l[i]) > 0 len(l[i]) len l[i] l i 0 dp2 = copy.copy(dp) dp2 copy.copy(dp) copy.copy copy copy dp now1 = 0 now1 0 k = 0 k 0 k1 = len(l[i]) k1 len(l[i]) len l[i] l i count = 0 count 0 while k < k1:
            if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
            count += dp2[now1]
            count %= mod
            now1 += 1
        #print(dp) k < k1 k k1 if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
             now1 == l[i][k] now1 l[i][k] [i] l i k dp[now1] += 1 dp[now1] dp now1 1 dp[now1] += count dp[now1] dp now1 count dp[now1] %= mod dp[now1] dp now1 mod k += 1 k 1 count += dp2[now1] count dp2[now1] dp2 now1 count %= mod count mod now1 += 1 now1 1 print((sum(dp)+1)%mod) print (sum(dp)+1)%mod sum(dp)+1 sum(dp) sum dp 1 mod n,m = map(int,input().split()) map(int,input().split()) n now = b[i] b[i] now dp2 = copy.copy(dp) copy.copy(dp) dp2 k1 = len(l[i]) len(l[i]) k1 count = 0 0 count now1 += 1 1 now1 a = s s a s = list(map(int,input().split())) list(map(int,input().split())) s a = t t a count %= mod mod count mod = 10**9+7 10**9+7 mod m = copy.copy(c) copy.copy(c) m l = [] [] l m = map(int,input().split()) map(int,input().split()) m n = copy.copy(m) copy.copy(m) n count += dp2[now1] dp2[now1] count k = 0 0 k now1 = 0 0 now1 c = copy.copy(n) copy.copy(n) c k += 1 1 k b = s s b t = list(map(int,input().split())) list(map(int,input().split())) t b = t t b bl = [] [] bl dp = [0 for i in range(max(n,m))] [0 for i in range(max(n,m))] dp
import copy
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp = [0 for i in range(max(n,m))]
mod = 10**9+7
if n > m:
    a = s
    b = t
else:
    a = t
    b = s
    c = copy.copy(n)
    n = copy.copy(m)
    m = copy.copy(c)
l = []
for i in range(m):
    now = b[i]
    bl = []
    for j in range(n):
        if now == a[j]:
            bl.append(j)
    l.append(bl)
for i in range(m):
    if len(l[i]) > 0:
        dp2 = copy.copy(dp)
        now1 = 0
        k = 0
        k1 = len(l[i])
        count = 0
        while k < k1:
            if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
            count += dp2[now1]
            count %= mod
            now1 += 1
        #print(dp)
print((sum(dp)+1)%mod)