let ans, s = ref max_int, read_line ()
let _ = String.(iter (fun d -> let c, l, cs = ref 0, ref @@ length s, Array.init (length s) (get s) in
  while List.exists ((<>) d) @@ Array.(to_list @@ sub cs 0 !l) do for i = 1 to !l - 1 do if cs.(i) = d then cs.(i - 1) <- d done; decr l; incr c done; ans := min !ans !c) s); Printf.printf "%d\n" !ans