program sample
    implicit none
    character(100000)::s,t
    integer(8) :: i,j,k,m,n,search
    integer(8)::a,b,c,d,ans
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) s
    read(*,*)t
    n=len_trim(s)
    m=len_trim(t)
    a=1
    b=n
    c=1
    search=0
    ans=0
    do i=1,m
        do 
            if(t(i:i) .eq. s(a:a))then
                b=a
                a=b+1
                ans=ans+1
                search=0
                exit
            elseif(a==b .and. search==1)then
                write(*,*)-1
                stop
            end if
            a=a+1
            ans=ans+1
            if(a==n+1)then
                a=1
                search=1
                c=c+1
                if(c>100)then
                    write(*,*)-1
                    stop
                end if
            end if

        enddo
        if(a==n+1)then
            a=1
            c=c+1
            if(c>100)then
                write(*,*)-1
                stop
            end if
        end if
    end do
    write(*,*)ans




    stop
end program sample
  

