program kadai
   implicit none
    character(len=100000)  ::  s
    character(len=100000)  ::  t
    character(len=1),allocatable  ::  sos(:)
    character(len=1),allocatable  ::  sot(:)
    integer  ::  i,all
    integer(8)  ::  count
    integer  ::  size_s,size_t
    integer  ::  flag,sflag,j

    read(*,*) s
    read(*,*) t

    size_s=len_trim(s)
    size_t=len_trim(t)
    allocate(sos(size_s))
    allocate(sot(size_t))
    !write(*,*) len_trim(s),len_trim(t)

    do i=1,size_s
        sos(i)=s(i:i)
    end do
    do i=1,size_t
        sot(i)=t(i:i)
    end do

    call qsort(sos)
    call qsort(sot)
    !write(*,*) sos
    !write(*,*) sot
    j=1
    flag=0
    sflag=0
    do i=1,size_s
        if (sos(i)==sot(j)) then
            do while(sos(i)==sot(j))
                flag=flag+1
                j=j+1
            end do
        end if
        if (j==size_t+1) then
            sflag=1
            exit
        end if
    end do

    if (sflag==0) then
        write(*,*) -1
        stop
    end if


    all=1
    count=1
    j=1
    do
        do i=1,size_s
            if (s(i:i)==t(j:j)) then
                j=j+1
            end if
            count=count+1
            if (j==size_t+1) then
                write(*,*) count-1
                stop
            end if
        end do
    end do

stop
contains

subroutine swap(a,b)
implicit none
character(len=*),intent(inout)  ::  a,b
character(len=10)  ::  c
c=a
a=b
b=c
end subroutine swap

subroutine qsort(x)
implicit none
character(len=*), intent(inout)  ::  x(:)
integer  ::  first,last
first=1
last=size(x)
call q2sort(x,first,last)
return
end subroutine qsort

recursive subroutine q2sort(x,first,last)
implicit none
character(len=*), intent(inout)  ::  x(:)
integer, intent(inout) ::  first,last
integer  ::  fir, las
integer  ::  i,j
character(len=10)  ::  n
n=x((first+last)/2)
i=first
j=last
do
do while (x(i)<n)
i=i+1
end do
do while(x(j)>n)
j=j-1
end do
if (i>j .or. i==j) then
exit
end if
call swap(x(i),x(j))
i=i+1
j=j-1
end do
if (first<i-1) then
las=i-1
call q2sort(x,first,las)
end if
if (last>j+1) then
fir=j+1
call q2sort(x,fir,last)
end if
end subroutine q2sort


end program kadai
