import Control.Applicative
import Control.Monad


canditate :: [Int] -> [Int]
canditate [] = [0]
canditate (x:xs) =
  if x == 1
    then (+) <$> [1,11] <*> canditate xs
  else
    (+) <$> [x] <*> canditate xs

reshape :: [Int] -> [Int]
reshape [] = []
reshape (x:xs) = if x >= 10 then 10 : reshape xs else x : reshape xs

solver :: [Int] -> Int
solver xs =
  let ys = canditate $ reshape xs
      zs = filter (<= 21) ys
  in
      if null zs
        then 0
      else
        maximum zs

main :: IO()
main = do
  line <- map (read :: String -> Int) . words <$> getLine
  unless (line == [0]) $ do
    print $ solver line
    main