let int_of_char c = (Char.code c) - 48;;

let to_list n =
  let rec loop l = function
      0 -> l
    | i -> loop ((int_of_char n.[10-i]) mod 10::l) (i-1)
  in loop [] 10
;;

let bottom list =
  let f x y =
    if snd x = -1 then ([], y)
    else ((((snd x) + y) mod 10)::(fst x), y)
  in
  let rec loop = function
      [e] -> e
    | l -> List.fold_left f ([], -1) l |> fst |> List.rev |> loop
  in loop list
;;

let () =
  let rec read () =
    try let l = read_line () |> to_list in
        Printf.printf "%d\n" (bottom l);
        read ()
    with
      End_of_file -> ()
  in read ()
;;