#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

bool solve(string s, char except)
{
	s.erase(s.find(except), 2);

	for (int i = 0; i < 4; i++)
	{
		if (count(s.begin(), s.end(), s[0]) >= 3)
		{
			s.erase(0, 3);
		}
		else if (count(s.begin(), s.end(), s[0] + 1) > 0 && count(s.begin(), s.end(), s[0] + 2) > 0)
		{
			s.erase(s.find(s[0] + 2), 1);
			s.erase(s.find(s[0] + 1), 1);
			s.erase(0, 1);
		}
	}

	if (s.size() == 0) return true;
	else return false;
}


int main()
{
	string str;
	while (cin >> str)
	{
		bool IsFirst = true;
		
		for (int i = 1; i < 10; i++)
		{
			if (count(str.begin(), str.end(), char(i + '0')) == 4) continue;
			string s = str;
			s.push_back(char(i + '0'));
			sort(s.begin(), s.end());

			for (int j = 1; j < 10; j++)
			{
				if (count(s.begin(), s.end(), char(j + '0')) >= 2)
				{
					if (solve(s, char(j + '0')))
					{
						if (!IsFirst) cout << ' ';
						cout << i;
						IsFirst = false;
						break;
					}
				}
			}
		}

		if (IsFirst) cout << 0;
		cout << endl;
	}

	return 0;
}