n = gets.to_i
while n >= 10
    n = n.to_s.split('').map(&:to_i).sum
end
p n