while line = gets
  data = line.chomp.split(//).map(&:to_i)
  while data.size != 1
    next_data = []
    for i in 0..data.size-2
      next_data << (data[i] + data[i+1]).to_s[-1].to_i
    end
    data = next_data
  end
  puts data[0]
end