program strings_of_impurity
  implicit none
  character(100000) :: s, t
  integer :: n, m, i, j, k, idx(26) = -1, nxt(100000,26) = 0
  integer(8) :: ans = 0_8
  read(*,*) s
  read(*,*) t
  n = len_trim(s)
  m = len_trim(t)
    do i = n, 1, -1
    j = ord(s(i:i))
    idx(j) = n+i
  end do
  do i = 1, m
    j = ord(t(i:i))
    if (idx(j) < 0) then
      write(*,'(i0)') -1
      stop
    end if
  end do
  do i = n, 1, -1
    k = ord(s(i:i))
    do j = 1, 26
      if (idx(j) < 0) cycle
      nxt(i,j) = idx(j)-i
    end do
    idx(k) = i
    if (s(i:i) == t(1:1)) ans = int(i,8)
  end do
  do i = 2, m
    j = int(mod(ans-1_8,int(n,8)),4)+1
    ans = ans+int(nxt(j,ord(t(i:i))),8)
  end do
  write(*,'(i0)') ans
contains
  integer function ord(s)
    character(1), intent(in) :: s
    ord = ichar(s)-96
  end
end program strings_of_impurity