let s = read_line ()
let t = read_line ()

let s_len = String.length s
let t_len = String.length t

let ch_pos =
  let ss = s ^ s in
  let len = s_len * 2 in
  let rec f arr i =
    if i = -1 then arr
    else begin
      arr.(i) <- Array.copy arr.(i + 1);
      arr.(i).(int_of_char ss.[i] - int_of_char 'a') <- i;
      f arr (i - 1)
    end
  in
  f (Array.init (len + 1) (fun _ -> Array.make 26 (-1))) (len - 1)

let rec loop sum i pos =
  if i = t_len then
    print_int sum
  else 
    let next = ch_pos.(pos + 1).(int_of_char t.[i] - int_of_char 'a') in
    if next = -1 then begin
      print_int (-1); exit 0;
    end else loop (sum + next - pos) (i + 1) (next mod s_len)

let () = 
  let start = ch_pos.(0).(int_of_char t.[0] - int_of_char 'a') in
  if start = -1 then print_int (-1) else loop (start + 1) 1 start