import qualified Data.Map
import qualified Data.List as L

main :: IO()
main = do
  s <- getLine
  t <- getLine
  print $ slv s t

slv :: String -> String -> Integer
slv s t | check s t /= True = -1
        | otherwise = slv' s t

slv' :: String -> String -> Integer
slv' s t = search creMap t (fromIntegral (length s)) 0 0
  where creMap = createMap s

search :: Data.Map.Map Char [Integer] -> String -> Integer -> Integer -> Integer -> Integer
search creMap [] _ _ ret = ret
search creMap (t:ts) len nowIndex ret | val > nowIndex = search mp ts len val (ret + (val - nowIndex))
                                      | otherwise = search mp ts len val (ret + (len - nowIndex + val))
  where mp = Data.Map.adjust (tail) t creMap
        val = head $ creMap Data.Map.! t

createMap :: String -> Data.Map.Map Char [Integer]
createMap str = Data.Map.map cycle $ Data.Map.fromListWith (++) $ zip str $ map (\x -> [x]) [1..]

check :: String -> String -> Bool
check s t = tmp1 == tmp2
  where tmp1 = map head $ L.group $ L.sort s
        tmp2 = map head $ L.group $ L.sort t