#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	while(true){
		string tmp;
		cin >> tmp;
		if(cin.eof()) break;
		map<int, int> table;
		for(int i = 0; i < tmp.size(); i++){
			if(table.count(tmp[i] - '0')) table[tmp[i] - '0']++;
			else table[tmp[i] - '0'] = 1;
		}

		vector<int> answer;
		for(int i = 1; i <= 9; i++){
			map<int, int> table2 = table;
			
			if(table2.count(i)){
				if(table2[i] < 4) table2[i]++;
				else continue;
			}
			else table2[i] = 1;
			
			for(int j = 1; j <= 9; j++){
				if(table2.count(j) && table2[j] > 1){
					map<int, int> table3 = table2;
					table3[j] -= 2;
					
					for(int k = 1; k < 8; k++){
						if(table3.count(k) && table3.count(k + 1) && table3.count(k + 2)){
							while(table3[k] && table3[k + 1] && table3[k + 2]){
								if(table3[k] % 3 == 0) break;
								table3[k]--;
								table3[k + 1]--;
								table3[k + 2]--;
							}
						}
					}
					bool OK = true;
					for(int k = 0; k <= 9; k++){
						if(table3.count(k) && (table3[k] && table3[k] != 3)) OK = false;
					}
					if(OK){
						bool flag = false;
						for(int k = 0; k < answer.size(); k++){
							if(i == answer[k]) flag = true;
						}
						if(!flag) answer.push_back(i);
					}
				}		
			}

			
		}

		if(!answer.size()) answer.push_back(0);
		for(int i = 0; i < answer.size(); i++){
			if(i) cout << " ";
			cout << answer[i];
		}
		cout << endl;
	}
	return 0;
}