program abc130e
  implicit none
  integer(8),parameter :: md = 10**9+7
  integer :: n, m, i, j
  integer,dimension(:),allocatable :: s, t
  integer(8),dimension(:,:),allocatable :: dp
  read *, n, m
  allocate(s(n),t(m),dp(0:m,0:n))
  read *, s, t
  dp = 1
  do i = 1,n
     do j = 1,m
        if (s(i)==t(j)) then
           dp(j,i) = mod(dp(j-1,i)+dp(j,i-1),md)
        else
           dp(j,i) = mod(dp(j-1,i)+dp(j,i-1)-dp(j-1,i-1),md)
        end if
     end do
  end do
  print *, dp(m,n)
end program abc130e
