#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
/** Problem0169 : Blackjack **/
int main()
{
	int ans, one, t;
	string s;
	
	while (!cin.eof()) {
		getline(cin, s);
		if (s == "0") break;
		stringstream ss(s);
		
		ans=0; one=0;
		while (!ss.eof()) {
			ss >> t;
			if (2 <= t && t < 10)
				ans += t;
			else if (t == 1) {
				one++;
				ans+=11;
			} else {
				ans+=10;
			}
		}
		
		while (ans>21 && one>0) {
			one--;
			ans-=10;
		}
		
		if (ans > 21) ans=0;
		cout << ans << endl;
	}
	return 0;
}