main :: IO ()
main = do
  ls <- getLine
  if ls == "0"
    then return ()
    else do
      let ls' = map (read :: String -> Int) (words ls)
          ls'' = [min i 10 | i <- ls']
          ans = point ls''
      putStrLn $ show ans
      main


point :: [Int] -> Int
point ls
  | initScore > 21 = 0
  | initScore > 11 = initScore
  | (count 1 ls) == 0 = initScore
  | (count 1 ls) == 1 = initScore + 10
  | (count 1 ls) >= 2 && initScore > 1 = initScore + 10
  | otherwise = initScore + 20
  where initScore = sum ls
        count n ls = foldl f 0 ls
          where f i x
                  | x == n = i + 1
                  | otherwise = i