#include <iostream>
#include <deque>
#include <string>
#include <sstream>

using namespace std;

int main(void){
		string str;

		while(getline(cin,str)){
			deque<int> q;
			int tmp;
			istringstream iss(str);
			iss >> tmp;
			if(tmp == 0) break;
			if(tmp == 1){
				q.push_back(1);
				q.push_back(11);
			}else if(tmp >= 10){
				q.push_back(10);
			}else{
				q.push_back(tmp);
			}

			while(iss >> tmp){
				int times = q.size();
				for(int i=0;i<times;i++){
					if(tmp == 1){
						if(q.front() + 1 <= 21){
							q.push_back(q.front() + 1);
						}
						if(q.front() + 11 <= 21){
							q.push_back(q.front() + 11);
						}
					}else if(tmp >= 10){
						if(q.front() + 10 <= 21){
							q.push_back(q.front() + 10);
						}
					}else{
						if(q.front() + tmp <= 21){
							q.push_back(q.front() + tmp);
						}
					}
					q.pop_front();
				}
			}

			int ret=0;
			while(!q.empty()){
				if(q.front() >= 22){
					//do nothing
				}else if(q.front() > ret){
					ret = q.front();
				}
				q.pop_front();
			}
			cout << ret << endl;
		}
	return 0;
}