#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

bool rec(vector<int> v)
{
	if (v.size() == 0) { return true; }

	vector<int> count_(10, 0);

	for (int i = 0; i < v.size(); i++)
	{
		count_[v[i]] += 1;
	}

	for (int i = 1; i <= 9; i++)
	{
		if (count_[i] >= 3)
		{
			vector<int> v2;

			for (int j = 0; j < v.size(); j++)
			{
				if (v[j] != i)
				{
					v2.push_back(v[j]);
				}
			}

			if (rec(v2) == true)
			{
				return true;
			}
		}
	}

	for (int i = 1; i <= 7; i++)
	{
		if (count_[i] >= 1 && count_[i + 1] >= 1 && count_[i + 2] >= 1)
		{
			int ca = 0, cb = 0, cc = 0;

			vector<int> v2;

			for (int j = 0; j < v.size(); j++)
			{
				if ((v[j] != i || ca++ != 0) && (v[j] != i + 1 || cb++ != 0) && (v[j] != i + 2 || cc++ != 0))
				{
					v2.push_back(v[j]);
				}
			}

			if (rec(v2) == true)
			{
				return true;
			}
		}
	}

	return false;
}

bool check(vector<int> v)
{
	for (int i = 1; i <= 9; i++)
	{
		int count_ = 0;

		for (int j = 0; j < v.size(); j++)
		{
			if (v[j] == i)
			{
				count_++;
			}
		}

		if (count_ >= 2)
		{
			vector<int> v2;

			int cc = 0;

			for (int j = 0; j < v.size(); j++)
			{
				if (v[j] != i || cc++ >= 2)
				{
					v2.push_back(v[j]);
				}
			}

			if (rec(v2) == true)
			{
				return true;
			}
		}
	}

	return false;
}

int main()
{
	string S; vector<int> v(13);

	while (cin >> S)
	{
		for (int i = 0; i < 13; i++)
		{
			v[i] = S[i] - 48;
		}

		int count_ = 0;
		
		for (int i = 1; i <= 9; i++)
		{
			vector<int> v2 = v;

			v2.push_back(i);

			if (check(v2))
			{
				if (count_++)
				{
					cout << ' ';
				}

				cout << i;
			}

			cout << endl;
		}

		if (count_ == 0)
		{
			cout << 0 << endl;
		}
	}

	return 0;
}