module CharSet = Set.Make (Char)

let rec solve n c s =
  if List.for_all (( = ) c) @@ Array.to_list s then n
  else
    solve (n + 1) c (Array.init (Array.length s - 1) (fun i ->
      if s.(i) = c || s.(i + 1) = c then c
      else s.(i)))
let solve = solve 0

let () =
  let s = read_line () in
  let a = Array.init (String.length s) (fun i -> s.[i]) in
  CharSet.of_list (Array.to_list a)
  |> CharSet.elements
  |> List.map (fun c -> solve c a)
  |> List.fold_left min max_int
  |> Printf.printf "%d\n"