program prob5
    implicit none
    character(100005) :: s, t
    character(200010) :: ss
    logical :: x(26), y(26)
    integer, allocatable :: next(:,:)
    integer :: i, j, ans, ls, lt, first, tmp
    read(*,*) s, t
    ls = len_trim(s)
    lt = len_trim(t)
    ss = trim(adjustl(s)) // trim(adjustl(s))
    allocate(next(ls, 26))
    x = .false.
    y = .false.
    do i = 1, ls
        x(ichar(s(i:i)) - ichar('a') + 1) = .true.
    end do
    do i = 1, lt
        y(ichar(t(i:i)) - ichar('a') + 1) = .true.
    end do

    do i = 1, 26
        if((x(i) .eqv. .false.) .and. (y(i) .eqv. .true.)) then
            write(*,'(a)') "-1"
            stop
        end if
    end do

    do i = 1, 26
        if(x(i) .eqv. .false.) then
            cycle
        end if
        do j = 1, ls
            if(s(j:j) == char(ichar('a') - 1 + i)) then
                first = j
                exit
            end if
        end do

        tmp = ls + first
        do j = ls + first - 1, first, -1
            next(mod(j - 1, ls) + 1, i) = tmp - j
            if(ss(j:j) == char(ichar('a') - 1 + i)) then
                tmp = j
            end if
        end do
    end do

    do j = 1, ls
        if(s(j:j) == t(1:1)) then
            first = j
        end if
    end do
    tmp = first
    ans = first
    do i = 2, lt
        ans = ans + next(tmp, ichar(t(i:i)) - ichar('a') + 1)
        tmp = mod(ans - 1, ls) + 1
    end do


    write(*,*) ans

    deallocate(next)
    stop
contains
end program prob5