n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for b in s:
  d=a[:]
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=d[:]
print(a[-1])
     int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n,m =[int(i) for i in input().split()] n [int(i) for i in input().split()] m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i s=[int(i) for i in input().split()] s [int(i) for i in input().split()] int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i t=[int(i) for i in input().split()] t [int(i) for i in input().split()] a=[1]*(m+1) a [1]*(m+1) [1] 1 m+1 m 1 for b in s:
  d=a[:]
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=d[:] b s d=a[:] d a[:] a : k=0 k 0 for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
   j c enumerate(t) enumerate t d[j]=(k+d[j])%1000000007 d[j] d j (k+d[j])%1000000007 k+d[j] k d[j] d j 1000000007 if b==c:
      k=(k+a[j])%1000000007
   b==c b c k=(k+a[j])%1000000007 k (k+a[j])%1000000007 k+a[j] k a[j] a j 1000000007 d[-1]=(k+d[-1])%1000000007 d[-1] d -1 (k+d[-1])%1000000007 k+d[-1] k d[-1] d -1 1000000007 a=d[:] a d[:] d : print(a[-1]) print a[-1] a -1 k=(k+a[j])%1000000007 (k+a[j])%1000000007 k t=[int(i) for i in input().split()] [int(i) for i in input().split()] t a=d[:] d[:] a k=0 0 k n,m =[int(i) for i in input().split()] [int(i) for i in input().split()] n s=[int(i) for i in input().split()] [int(i) for i in input().split()] s a=[1]*(m+1) [1]*(m+1) a m =[int(i) for i in input().split()] [int(i) for i in input().split()] m d=a[:] a[:] d
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for b in s:
  d=a[:]
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=d[:]
print(a[-1])
    
