#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

int u[10];

bool solve(){
	bool f=false;
	int sum=0;
	for(int i=1;i<10;i++)sum+=u[i];
	if(sum==0)return true;
	for(int i=1;i<10;i++){
		if(u[i]>2){
			u[i]-=3;
			if(solve()){
				f=true;
			}
			u[i]+=3;
		}
	}
	for(int i=1;i<8;i++){
		if(u[i]>0&&u[i+1]>0&&u[i+2]>0){
			u[i]--;
			u[i+1]--;
			u[i+2]--;
			if(solve()){
				f=true;
			}
			u[i]++;
			u[i+1]++;
			u[i+2]++;
		}
	}
	return f;
}

int main(void){
	char buff[20];
	while(scanf("%s",buff)!=EOF){
		int d[10]={0};
		vector<int> v;
		for(int i=0;i<13;i++){
			d[buff[i]-'0']++;
		}
		for(int i=1;i<10;i++){
			for(int j=1;j<10;j++){
				u[j]=d[j];
			}
			if(u[i]==4)continue;
			if(u[i]>4){v.clear();break;}
			u[i]++;
			if(u[i]>4)continue;
			bool f=false;
			for(int j=1;j<10;j++){
				if(u[j]>1){
					u[j]-=2;
					if(solve()){
						f=true;
					}
					u[j]+=2;
				}
			}
			if(f)v.push_back(i);
		}
		if(v.size()==0)cout<<"0"<<endl;
		for(int i=0;i<v.size()-1;i++)cout<<v[i]<<" ";
		cout<<v[v.size()-1]<<endl;
	}
}