time = []
min = Float::INFINITY
min_1 = 9
5.times do
  x = gets.chomp
  if x[-1].to_i != 0 && x[-1].to_i <= min_1
    min_1 = x[-1].to_i
    min = x.to_i
  end
  time << x.to_i
end
time.delete_at(time.find_index(min))
puts time.inject(min){|a,b| a+b.ceil(-1) }
