let list_of_str s = Array.(to_list (init (String.length s) (fun i -> i, s.[i])))
let _ = Scanf.scanf "%s" @@ fun s ->
  let n, t = String.length s, list_of_str s in
  List.fold_left (fun z (_,c) ->
    List.fold_left (fun s (i, x) ->
      if x = c then i::s else s) [n] (List.rev t)
    |> List.fold_left (fun (d, j) i -> max d (i-j-1), i) (0, -1)
    |> fst |> min z) n t
  |> Printf.printf "%d\n"