#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
arr=[[0]*m for i in range(n)]
for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            arr[i][j] = 1
acum = [[0]*m for i in range(n)]
acum[0][0] = arr[0][0]
# for i in range(1,n):
#     acum[i][0] = acum[i-1][0] + arr[i][0]
# for j in range(1,m):
#     acum[0][j] = acum[0][j-1] + arr[0][j]
for i in range(n):
    for j in range(m):
        arr[i][j] += ((acum[i-1][j-1])*(arr[i][j]) if i-1 >= 0 and j-1 >= 0 else 0)
        acum[i][j] = (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) - (acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0) + arr[i][j]
        arr[i][j] %= mod; acum[i][j] %= mod
print(1+sum(map(sum,arr))%mod)
# print(*arr,sep="\n");print()
# print(*acum,sep="\n")

 import sys, math, itertools, collections, bisect sys math itertools collections bisect input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') input lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') sys.stdin.buffer.readline().rstrip().decode('utf-8') sys.stdin.buffer.readline().rstrip().decode sys.stdin.buffer.readline().rstrip() sys.stdin.buffer.readline().rstrip sys.stdin.buffer.readline() sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline rstrip decode 'utf-8' inf = float('inf') inf float('inf') float 'inf' mod = 10**9+7 mod 10**9+7 10**9 10 9 7 mans = inf mans inf ans = 0 ans 0 count = 0 count 0 pro = 1 pro 1 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]*m for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*m [0] 0 m arr=[[0]*m for i in range(n)] arr [[0]*m for i in range(n)] for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            arr[i][j] = 1 i range(n) range n for j in range(m):
        if S[i] == T[j]:
            arr[i][j] = 1 j range(m) range m if S[i] == T[j]:
            arr[i][j] = 1 S[i] == T[j] S[i] S i T[j] T j arr[i][j] = 1 arr[i][j] [i] arr i j 1 [0]*m for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*m [0] 0 m acum = [[0]*m for i in range(n)] acum [[0]*m for i in range(n)] acum[0][0] = arr[0][0] acum[0][0] [0] acum 0 0 arr[0][0] [0] arr 0 0 for i in range(n):
    for j in range(m):
        arr[i][j] += ((acum[i-1][j-1])*(arr[i][j]) if i-1 >= 0 and j-1 >= 0 else 0)
        acum[i][j] = (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) - (acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0) + arr[i][j]
        arr[i][j] %= mod; acum[i][j] %= mod i range(n) range n for j in range(m):
        arr[i][j] += ((acum[i-1][j-1])*(arr[i][j]) if i-1 >= 0 and j-1 >= 0 else 0)
        acum[i][j] = (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) - (acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0) + arr[i][j]
        arr[i][j] %= mod; acum[i][j] %= mod j range(m) range m arr[i][j] += ((acum[i-1][j-1])*(arr[i][j]) if i-1 >= 0 and j-1 >= 0 else 0) arr[i][j] [i] arr i j (acum[i-1][j-1])*(arr[i][j]) if i-1 >= 0 and j-1 >= 0 else 0 i-1 >= 0 and j-1 >= 0 i-1 >= 0 i-1 i 1 0 j-1 >= 0 j-1 j 1 0 (acum[i-1][j-1])*(arr[i][j]) acum[i-1][j-1] [i-1] acum i-1 i 1 j-1 j 1 arr[i][j] [i] arr i j 0 acum[i][j] = (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) - (acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0) + arr[i][j] acum[i][j] [i] acum i j (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) - (acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0) + arr[i][j] (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) - (acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0) (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) acum[i-1][j] if i-1>=0 else 0 i-1>=0 i-1 i 1 0 acum[i-1][j] [i-1] acum i-1 i 1 j 0 acum[i][j-1] if j-1>=0 else 0 j-1>=0 j-1 j 1 0 acum[i][j-1] [i] acum i j-1 j 1 0 acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0 i-1>=0 and j-1 >=0 i-1>=0 i-1 i 1 0 j-1 >=0 j-1 j 1 0 acum[i-1][j-1] [i-1] acum i-1 i 1 j-1 j 1 0 arr[i][j] [i] arr i j arr[i][j] %= mod arr[i][j] [i] arr i j mod acum[i][j] %= mod acum[i][j] [i] acum i j mod print(1+sum(map(sum,arr))%mod) print 1+sum(map(sum,arr))%mod 1 sum(map(sum,arr))%mod sum(map(sum,arr)) sum map(sum,arr) map sum arr mod pro = 1 1 pro n,m=map(int,input().split()) map(int,input().split()) n acum = [[0]*m for i in range(n)] [[0]*m for i in range(n)] acum T=list(map(int,input().split())) list(map(int,input().split())) T S=list(map(int,input().split())) list(map(int,input().split())) S input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') input ans = 0 0 ans inf = float('inf') float('inf') inf mod = 10**9+7 10**9+7 mod count = 0 0 count m=map(int,input().split()) map(int,input().split()) m mans = inf inf mans arr=[[0]*m for i in range(n)] [[0]*m for i in range(n)] arr
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
arr=[[0]*m for i in range(n)]
for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            arr[i][j] = 1
acum = [[0]*m for i in range(n)]
acum[0][0] = arr[0][0]
# for i in range(1,n):
#     acum[i][0] = acum[i-1][0] + arr[i][0]
# for j in range(1,m):
#     acum[0][j] = acum[0][j-1] + arr[0][j]
for i in range(n):
    for j in range(m):
        arr[i][j] += ((acum[i-1][j-1])*(arr[i][j]) if i-1 >= 0 and j-1 >= 0 else 0)
        acum[i][j] = (acum[i-1][j] if i-1>=0 else 0) + (acum[i][j-1] if j-1>=0 else 0) - (acum[i-1][j-1]if i-1>=0 and j-1 >=0 else 0) + arr[i][j]
        arr[i][j] %= mod; acum[i][j] %= mod
print(1+sum(map(sum,arr))%mod)
# print(*arr,sep="\n");print()
# print(*acum,sep="\n")


