let ioc c = int_of_char c - int_of_char 'a'

let s = read_line()
let t = read_line()
let n = String.length s
let m = String.length t
let d = Array.init 26 (fun _ -> Array.make (n + 1) ~-1)

let rec f i j s =
  if i = m then s + j
  else
    let k = ioc t.[i] in
    if d.(k).(0) = -1 then -1
    else
      let j = d.(k).(j) in
      if j = -1 then f (i + 1) (d.(k).(0) + 1) (s + n)
      else f (i + 1) (j + 1) s

let () =
  for i = 0 to n - 1 do
    d.(ioc s.[i]).(i) <- i
  done;

  Array.iter (fun d ->
    for i = 0 to n - 1 do
      let j = n - 1 - i in
      if d.(j) = -1 then
        d.(j) <- d.(j + 1)
      done
  ) d;

  d.(ioc s.[0]).(0) <- 0;

  Printf.printf "%d\n" (f 0 0 0)
