#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;
#define REP(i,n) for (int i=0; i<n; i++)

int sum(int x[]){
	int s=0;
	for (int i=1; i<10; i++) 
		s += x[i];
	return s;
}

bool check(int x[], int j=1){
	if (sum(x)==0) return true;
	for (int i=j; i<10; i++){
		int y[10];
		for (j=0; j<10; j++) y[j]=x[j];
		if (y[i]>=3){
			y[i]-=3;
			if (check(y,i)) return true;
			y[i]+=3;
		}
		if (i<8 && y[i]>0 && y[i+1]>0 && y[i+2]>0){
			y[i]--;
			y[i+1]--;
			y[i+2]--;
			if (check(y,i)) return true;
		}
	}
	return false;
}

int main(void){
	while (true){
		int n[10];
		REP(i,10) n[i]=0;
		string line;
		getline(cin,line);
		if (cin.eof()) break;
		for (char c: line) n[c-'0']++;

		bool f=false;
		for (int i=1;i<10;i++){
			int n1[10];
			REP(i1,10) n1[i1]=n[i1];
			if (n1[i]>=4) continue;
			else n1[i]++;
			vi atama;
			for (int j=1; j<10; j++)
				if (n1[j] >= 2){
					n1[j] -= 2;
					if (check(n1)){
						f = true;
						cout<<i<<" ";
						break;
					}
					n1[j] += 2;
				}
		}
		if (f) cout<<endl;
		else cout<<"0"<<endl;
	}
}