let s = read_line ()
let n, ans = String.length s, ref max_int
let _ = String.iter (fun d -> let b, c, l, cs = ref false, ref 0, ref n, Array.init n @@ fun i -> s.[i] in
  while not !b do let b2 = ref true in for i = 0 to !l - 1 do if cs.(i) <> d then b2 := false else if i > 0 then cs.(i - 1) <- cs.(i) done; decr l; b := !b2; if not !b then incr c done; ans := min !ans !c) s; Printf.printf "%d\n" !ans