let sum_of_digit n =
  let rec iter sum = function
    | 0 -> sum
    | i -> iter (sum + (i mod 10)) (i / 10)
  in iter 0 n 

let () =
  let rec loop () =
    match Scanf.scanf "%d\n" (fun n -> n) with
    | 0 -> ()
    | n ->
      Printf.printf "%d\n" (sum_of_digit n);
      loop ()
  in loop ()