while s = gets.chomp
  break if s == "0"

  res = 0
  one_n = 0

  s.split(" ").map{|e|
    e.to_i
  }.each{|e|
    if e == 1 then
      one_n += 1
    elsif e >= 10 && e <= 13
      res += 10
    else
      res += e
    end
  }

  f = false
  for i in 0..one_n #i: 1をそのまま使う数
    if res + i + 11*(one_n-i) <= 21 then
      res += i + 11*(one_n-i)
      f = true
      break
    end
  end

  if f
    puts res
  else
    puts 0
  end
end