menu = []
menui = []
bet = {"0" => 0,"1" => 9,"2" => 8,"3" => 7,"4" => 6,"5" => 5,"6" => 4,"7" => 3,"8" => 2,"9" => 1}

for i in 0..4 do
    n = gets.chomp.to_s
    menu.push(n)
    menui.push(n.to_i)
end

#p menu,menui

max = 0
cash = []
menus = []
for i in 0..4 do
    menus.push(menu[i].split(""))
    cash.push(bet[menus[i].last])
end

#p menus,cash

max = 0;
max_index = 0;
for i in 0..4 do
    if max < cash[i]
        max = cash[i]
        max_index = i
    end
end

#p max_index

temp = menui[max_index]
menui.delete_at(max_index)
menui.push(temp)

temp = 0
cash.delete_at(max_index)
cash.push(0)

#p menui,cash

puts menui.sum + cash.sum