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


read(*,*) n,m

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

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

sa=0
do i=1,n
    do j=1,m
        sa=sa+dp(i,j)
        if (sa>10**9+7) then
            sa=mod(sa,10**9+7)
        end if
    end do
end do

!write(*,*) dp
write(*,*) mod(sa+1,10**9+7)


stop
contains

end program kadai