let s = read_line ()
let n, ans = String.length s, ref max_int
let _ = Char.(for i = code 'a' to code 'z' do let d, b, c, l, cs = chr i, 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 done); Printf.printf "%d\n" !ans