while gets
    arr=Array.new
    arr=$_.chomp.split(//).map(&:to_i)
    while true
        i=0
        while true
            break if(arr[i+1]==nil)
            arr[i]=arr[i]+arr[i+1]
            i+=1
        end
        arr.pop
        break if(arr.size==1)
    end
    puts arr.join.split(//).last
end