let line = input_line stdin

let pr x = print_endline (string_of_int x)

let explode s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l) in
  exp (String.length s - 1) []

let seq = explode line
          |> List.map (fun x -> if x = '0' then 0 else 1)

let flip = List.map (fun x -> if x = 0 then 1 else 0) 

let contraction seq =
  let seq = if List.hd seq = 0 then flip seq else seq in
  let rec iter cnt pre res = function
    | x :: xs -> if pre = x then iter (cnt+1) x res xs
                 else iter 1 x ((x,cnt) :: res) xs
    | [] -> (pre,cnt) :: res in
  iter 0 (List.hd seq) [] seq |> List.rev

let rec last = function
  | (x,x') :: (y,y') :: (z,z') :: [] -> if z = 0 then x' + y'
                                        else y' + z'
  | (x,x') :: (y,y') :: [] -> y'
  | (x,x') :: [] -> x'
  | _ :: xs -> last xs
  | _ -> failwith "last"

let top = function
  | (x,x') :: (y,y') :: _ -> x' + y'
  | (x,x') :: [] -> x'
  | [] -> failwith "top"

let cnt = seq |> contraction

let () = min (last cnt) (top cnt)
       |> pr
