#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

bool bt (map<int,int> & curr, bool head )
{
	for (int i = 1; i <= 9; i++ ){
		if (curr[i] == 4 || curr[i] == 3 ){
			curr[i] -= 3;
			if (bt (curr, head ) ) return true;
			curr[i] += 3;
		} // end if
	} // end for

	for (int i = 1; i <= 7; i++ ){
		if (curr[i] >= 1 && curr[i+1] >= 1 && curr[i+2] >= 1 ){
			curr[i]--; curr[i+1]--; curr[i+2]--;
			if (bt (curr, head ) ) return true;
			curr[i]++; curr[i+1]++; curr[i+2]++;
		} // end if
	} // end for

	for (int i = 1; i <= 9; i++ ){
		if (curr[i] == 2 && !head ){
			curr[i] -= 2; head = true;
			if (bt (curr, head ) ) return true;
			curr[i] += 2; head = false;
		} // end if
	} // end for

	bool ok = true;
	for (int i = 1; i <= 9; i++ ){
		if (curr[i] == 0 ) continue;
		ok = false;
		break;
	} // end for

	if (ok && head ){
		return true;
	} // end if

	return false; 
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Puzzle", "r", stdin );
	string str = "";
	while (getline (cin, str ) ){
		set<int> res;
		map<int,int> pai; pai.clear();
		int n = str.length();
		rep (i, n ){
			pai[(int)(str[i] - '0' )]++;
		} // end rep
		vector<int> cand; cand.clear();
		for (int i = 1; i <= 9; i++ ){
			if (pai[i] >= 0 && pai[i] < 4 ) cand.push_back (i );
		} // end for

		rep (i, cand.size() ){
			map<int,int> curr = pai;
			curr[cand[i]]++;
			if (bt (curr, false ) ){
				res.insert (cand[i] );
			} // end if
		} // end rep

		if (res.empty() ){
			cout << 0 << endl;
		}else{
			set<int>::iterator it = res.begin();
			for (int i = 0; it != res.end(); it++, i++ ){
				cout << (*it) << (i != res.size() - 1 ? ' ' : '\n' );
			} // end for
		} // end if
	} // end loop
		
	return 0;
}