loop do
  a = gets.split.map(&:to_i)
  break if a[0]==0
  c=0
  a.map!{|x| x>9 ? 10 : x}
  sum = a.inject(0){|x,y|
    if y==1
      c+=1
    end
    x+y}
  unless c==0
    if sum>21
      sum-=10
    elsif sum<12
      sum+=10
    end
  end
  sum = 0 if sum>21
  puts sum
end