program kadai
   implicit none
integer(8)  ::  n,m,i,j,a,b
integer,allocatable  ::  s(:),t(:)
integer(8),allocatable  ::  dp(:,:),sum(:,:)
integer(8)  ::  sa


read(*,*) n,m

allocate(s(n))
allocate(t(m))
allocate(dp(n,m))
allocate(sum(n,m))
read(*,*) s
read(*,*) t

sum=0
dp=0
do i=1,n
    do j=1,m
        if (s(i)==t(j)) then
            if (i>1 .and. j>1) then
                dp(i,j)=sum(i-1,j-1)
            end if
            dp(i,j)=dp(i,j)+1
        else
            dp(i,j)=0
        end if
        if (i>1 .and. j>1) then
            sum(i,j)=sum(i-1,j)+sum(i,j-1)-sum(i-1,j-1)+dp(i,j)
        elseif (i==1 .and. j>1) then
            sum(1,j)=sum(1,j-1)+dp(1,j)
        elseif (i>1 .and. j==1) then
            sum(i,1)=sum(i-1,1)+dp(i,1)
        else
            sum(1,1)=dp(1,1)
        end if
        sum(i,j)=mod(sum(i,j),10**9+7)
    end do
end do


write(*,*) sum(n,m)+1


stop
contains

end program kadai