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

bool ck2(vi h){
	rep(i,9){
		if(h[i+1]>2)h[i+1]-=3;
		while(h[i]>0){
			h[i]--; h[i+1]--; h[i+2]--;
			if(h[i+1]<0||h[i+2]<0)return 0;
		}
	}
	return 1;
}
bool ck(vi h){
	bool suc;
	rep(pr,9){
		if(h[pr+1]>1){
			h[pr+1]-=2;
			suc=ck2(h);
			h[pr+1]+=2;
			if(suc)return 1;
		}
	}
	return 0;
}
int main(){
	char buf[20];
	while(cin>>buf){
		vi hand(14); bool flag=0;
		rep(i,13)hand[buf[i]-'0']++;
		
		rep(ad,9){
			if(hand[ad+1]>3)continue;
			hand[ad+1]++;
			if(ck(hand)){
				if(flag)cout<<" ";
				cout<<ad+1;
				flag=1;
			}
			hand[ad+1]--;
		}
		if(!flag)cout<<0<<endl;
		else cout<<endl;
	}
	return 0;
}