var n = String(readLine()!) while n.count > 1{ let a = Array(n) let b = a.map{String($0)} let c = b.map{Int($0)!} let d = c.reduce(0) {$0 + $1} n = String(d) } print(n)