#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int index(char c){
	return (int)c - 48;
}

bool three(int a, int b, int c){
	if(a == b && a == c) return true;
	if(b == a + 1 && c == b + 1) return true;
	return false;
}

bool head(int a, int b){
	if(a == b){
		return true;
	}else{
		return false;
	}
}

bool threes(int a[], int n){
	for(int i = 0; i < n; i++){
		if(!three(a[3*i],a[3*i+1],a[3*i+2])) return false;
	}
	return true;
}


bool able(int num[14]){
	int a[12];
	for(int j = 0; j < 13; j++){
		if(head(num[j], num[j+1])){
			int k = 0;
			while(k < j){
				a[k] = num[k];
				k++;
			}
			while(k < 12){
				a[k] = num[k+2];
				k++;
			}
			if(threes(a,4)) return true;
			int b[9];
			for(int l= 0; l < 10; l++){
				if(three(a[l],a[l+1],a[l+2])){
					int m = 0;
					while(m < l){
						b[m] = a[m];
						m++;
					}
					while(m < 9){
						b[m] = a[m+3];
						m++;
					}
					if(threes(b,3)) return true;
					int c[6];
					for(int n = 0; n < 7; n++){
						if(three(b[n],b[n+1],b[n+2])){
							int o = 0;
							while(o < n){
								c[o] = b[o];
								o++;
							}
							while(o < 6){
								c[o] = b[o+3];
								o++;
							}
							if(threes(c,2)) return true;
							int d[3];
							for(int p = 0; p < 4; p++){
								if(three(c[p],c[p+1],c[p+2])){
									int q = 0;
									while(q < p){
										d[q] = c[q];
										q++;
									}
									while(q < 3){
										d[q] = c[q+3];
										q++;
									}
									if(threes(d,1)) return true;
								}
							}
						}
					}

				}
			}
		}
	}
	return false;
}

bool judge(int num[14]){
	sort(num, num+14);
	if(able(num)) return true;
	return false;
}


int main(){
	string s;
	while(cin >> s){
		int nums[14];
		int count = 0;
		string::size_type size = s.size();
		for(int i = 1; i <= 9; i++){
			for(string::size_type st = 0; st < size; st++)
			{
				nums[st] = index(s[st]);
			}
			int c = 0;
			for(int j = 0; j < 13; j++){
				if(nums[j] == i) c++;
			}
			if(c < 4){
				nums[13] = i;
				if(judge(nums)){
					if(count){
						cout << " " << i;
					}else {
						cout<< i;
					}
					count++;
				}
			}
		}
		if(count == 0) cout << 0;
		cout << endl;
	}
	return 0;
}