def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[n,m]=i2()
s=i2()
t=i2()
x=10**9+7
cs=[[0 for i in range(2*10**3)]for j in range(2*10**3)]
y=0
for i in range(n):
 if s[i]==t[0]:
   y+=1
 cs[i][0]=y+0
y=0
for i in range(m):
 if s[0]==t[i]:
   y+=1
 cs[0][i]=y+0
for i in range(1,n):
 for j in range(1,m):
  if s[i]==t[j]:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]+1)%x
  else:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1])%x
print((cs[n-1][m-1]+1)%x) def i1():
 return int(input()) i1 return int(input()) int(input()) int input() input def i2():
 return [int(i) for i in input().split()] i2 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 return [int(i) for i in input().split()] [int(i) for i in input().split()] [n,m]=i2() [n,m] n m i2() i2 s=i2() s i2() i2 t=i2() t i2() i2 x=10**9+7 x 10**9+7 10**9 10 9 7 [0 for i in range(2*10**3)]for j in range(2*10**3) for j in range(2*10**3) j range(2*10**3) range 2*10**3 2 10**3 10 3 for j in range(2*10**3) [0 for i in range(2*10**3)] cs=[[0 for i in range(2*10**3)]for j in range(2*10**3)] cs [[0 for i in range(2*10**3)]for j in range(2*10**3)] y=0 y 0 for i in range(n):
 if s[i]==t[0]:
   y+=1
 cs[i][0]=y+0 i range(n) range n if s[i]==t[0]:
   y+=1
  s[i]==t[0] s[i] s i t[0] t 0 y+=1 y 1 cs[i][0]=y+0 cs[i][0] [i] cs i 0 y+0 y 0 y=0 y 0 for i in range(m):
 if s[0]==t[i]:
   y+=1
 cs[0][i]=y+0 i range(m) range m if s[0]==t[i]:
   y+=1
  s[0]==t[i] s[0] s 0 t[i] t i y+=1 y 1 cs[0][i]=y+0 cs[0][i] [0] cs 0 i y+0 y 0 for i in range(1,n):
 for j in range(1,m):
  if s[i]==t[j]:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]+1)%x
  else:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1])%x i range(1,n) range 1 n for j in range(1,m):
  if s[i]==t[j]:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]+1)%x
  else:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1])%x j range(1,m) range 1 m if s[i]==t[j]:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]+1)%x
  else:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1])%x s[i]==t[j] s[i] s i t[j] t j cs[i][j]=(cs[i-1][j]+cs[i][j-1]+1)%x cs[i][j] [i] cs i j (cs[i-1][j]+cs[i][j-1]+1)%x cs[i-1][j]+cs[i][j-1]+1 cs[i-1][j]+cs[i][j-1] cs[i-1][j] [i-1] cs i-1 i 1 j cs[i][j-1] [i] cs i j-1 j 1 1 x cs[i][j]=(cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1])%x cs[i][j] [i] cs i j (cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1])%x cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1] cs[i-1][j]+cs[i][j-1] cs[i-1][j] [i-1] cs i-1 i 1 j cs[i][j-1] [i] cs i j-1 j 1 cs[i-1][j-1] [i-1] cs i-1 i 1 j-1 j 1 x print((cs[n-1][m-1]+1)%x) print (cs[n-1][m-1]+1)%x cs[n-1][m-1]+1 cs[n-1][m-1] [n-1] cs n-1 n 1 m-1 m 1 1 x s=i2() i2() s y+=1 1 y y+=1 1 y t=i2() i2() t y=0 0 y x=10**9+7 10**9+7 x def i1():
 return int(input()) def i1():
 return int(input()) i1 cs=[[0 for i in range(2*10**3)]for j in range(2*10**3)] [[0 for i in range(2*10**3)]for j in range(2*10**3)] cs def i2():
 return [int(i) for i in input().split()] def i2():
 return [int(i) for i in input().split()] i2 y=0 0 y
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[n,m]=i2()
s=i2()
t=i2()
x=10**9+7
cs=[[0 for i in range(2*10**3)]for j in range(2*10**3)]
y=0
for i in range(n):
 if s[i]==t[0]:
   y+=1
 cs[i][0]=y+0
y=0
for i in range(m):
 if s[0]==t[i]:
   y+=1
 cs[0][i]=y+0
for i in range(1,n):
 for j in range(1,m):
  if s[i]==t[j]:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]+1)%x
  else:
   cs[i][j]=(cs[i-1][j]+cs[i][j-1]-cs[i-1][j-1])%x
print((cs[n-1][m-1]+1)%x)