module CharMap = Map.Make (Char)

let () =
  let s = read_line () in
  let t = read_line () in
  let skip = Array.make (String.length s + 1) CharMap.empty in
  for i = String.length s - 1 downto 0 do
    skip.(i) <- CharMap.add s.[i] i skip.(i + 1)
  done;
  skip.(String.length s) <- skip.(0);
  for i = String.length s - 1 downto 0 do
    skip.(i) <- CharMap.add s.[i] i skip.(i + 1)
  done;
  Printf.printf "%d\n" @@
  match
    Array.fold_left (fun (i, n) c ->
      let j = CharMap.find c skip.(i) in
      (j + 1, n + if j < i then 1 else 0)) (0, 0) @@
    Array.init (String.length t) (String.get t)
  with
  | exception Not_found -> -1
  | (i, n) -> n * String.length s + i
