#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <sstream>
using namespace std;

int limit[10];
vector<string> now;
vector<string> able;
vector<string> ableHead;
bool flag;

vector<int> allCount(vector<string>tmp){
	vector<int> ret(10,0);
	
	for(int si=0;si<tmp.size();si++){	
		for(int i=0;i<tmp[si].length();i++){
			ret[tmp[si][i]-'0']++;
		}
	}
	return ret;
}

bool malCheck(vector<string> tmp){
	vector<int> t = allCount(tmp);
	for(int i=0;i<10;i++){
		if(t[i]>limit[i])return true;
	}
	return false;
}

bool wantCheck(string s){
	if(s[1]==s[0]+1|| s[0] == s[1])return false;
	return true;
}

void bt2(){
	/* KèI[o[µ½ç²¯oµ */
	if(malCheck(now))return;
	
	/* 4R Êqª»ëÁ½Èç */
	if(now.size() == 5){
		flag = true;
		return;
	}
	
	for(int i=0;i<able.size();i++){
		vector<string> t = now;
		now.push_back(able[i]);
		bt2();
		now = t;
	}
}

int search(string s){
	now.clear();able.clear();ableHead.clear();
	fill(limit,limit+10,0);
	string chk;
	sort(s.begin(),s.end());
	chk = s;
	chk.erase(unique(chk.begin(),chk.end()),chk.end());
	
	/*Â¦*/
	for(int i=0;i<s.length();i++)limit[s[i]-'0']++;
	
	/* q Æ ª */
	for(int i=0;i<chk.length();i++){
	
		/* q */
		if(count(s.begin(),s.end(),chk[i]) >= 3){
			string t="";
			t+=chk[i];t+=chk[i];t+=chk[i];
			able.push_back(t);
		}
		
		/* ª */
		if(count(s.begin(),s.end(),chk[i]) >= 2){
			string t="";
			t+=chk[i];t+=chk[i];
			ableHead.push_back(t);
		}
		
	}
	/* q */
	for(int i=0;i<chk.length()-2;i++){
		if(chk[i+1]==chk[i]+1 && chk[i+2]==chk[i]+2){
			string t="";
			t+=chk[i];t+=chk[i]+1;t+=chk[i]+2;
			able.push_back(t);
		}
	}
	
	flag = false;
	
	/* ªÒ¿Tµ */
	for(int i=0;i<ableHead.size();i++){
		now.push_back(ableHead[i]);
		bt2();
		now.pop_back();
	}
	return flag;
}

int main(){
	string str,s;
	while( cin >> str ) {
		if(str.length() != 13){
			continue;
		}
		bool ret,f = false;
		for(int i=1;i<=9;i++){	
			if(count(str.begin(),str.end(),'0'+i)>=4)continue;
			s = str; s+='0'+i;
			ret = search(s);
			if(ret){
				cout << (f?" ":"") << i;
				f = true;
			}
		}
		cout << (f?"":"0") << endl;
	}
}