#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	char buf[512];
	while (cin.getline(buf, sizeof(buf)), *buf != '0')
	{
		stringstream ss(buf);
		int total = 0;
		int one = 0;
		int c;
		while (ss >> c)
		{
			if (c == 1)
			{
				total += 11;
				++one;
			}
			else if (c >= 10)
				total += 10;
			else
				total += c;
		}
		while (total > 21 && one--)
			total -= 10;

		if (total <= 21)
			printf("%d\n", total);
		else
			puts("0");
	}

	return 0;
}