import Data.Char
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.Monad
import qualified Data.IntSet as S

main = do
    ss <- zipWith (\i c -> (ord c - ord 'a', i)) [1..] <$> getLine
    ts <- map (\c -> ord c - ord 'a') <$> getLine
    let n = length ss
    let abc = V.create $ do
            vec <- VM.replicate 26 S.empty
            forM_ ss $ \(c,i) -> do
                VM.modify vec (S.insert i) c
            forM_ [0..25] $ \c -> do
                s <- VM.read vec c
                when (not (S.null s)) $ do
                    let m = S.findMin s
                    VM.modify vec (S.insert (m+n)) c
            return vec
    
    let f Nothing _ = Nothing
        f (Just (k,i)) c = (\j -> if j >= n then (k+1,j-n) else (k,j)) <$> S.lookupGT i (abc V.! c)
    
    let ans = case (foldl' f (Just (0,-1)) ts) of
               Just (k,i) -> n*k + i
               _ -> -1
    
    print ans