while ((str = gets()) != "0\n")
  hand = str.split()
  point = 0
  one = 0
  hand.each() do |c|
    card = c.to_i()
    if (card == 1)
      one += 1
    end
    point += card
  end
  while (one > 0)
    if (point + 10 <= 21)
      point += 10
      one -= 1
    else 
      break
    end
  end
  if (point > 21)
    point = 0
  end
  puts(point)
end