import Control.Monad
import Data.Char
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Set as S
main=print.solve.B.lines=<<B.getContents
solve[s,t]=maybe(-1)(uncurry(+)).foldM g(0,0).map f.B.unpack$t where
  n=B.length s
  as=V.accum(flip S.insert)(V.replicate 26 S.empty).(`zip`[1..]).map f.B.unpack$s
  g(k,i)c=case S.lookupGT i$as V.! c of
    Just(j) -> Just(k,j)
    Nothing -> case S.lookupGT 0$as V.! c of
      Just(j) -> Just(k+n,j)
      Nothing -> Nothing
f c=ord c-ord 'a'