#include <iostream>
#include <vector>
#include <stack>
#include <string>

void show(const std::vector<int> &vec) {
	for (const auto &v : vec) {
		std::cout << v << " ";
	}
	std::cout << std::endl;
}

class State {
public:
	State(const std::vector<int> &);
	bool can_make_seq() const;
	bool can_make_double() const;
	bool can_make_triple() const;
	void make_seq();
	void make_double();
	void make_triple();
	void revert();
	bool can_add_one(const int &) const;
	void add_one(const int &);
	bool empty() const;
private:
	enum class Order { Seq, Double, Triple, Add };
	std::vector<int> state;
	std::stack<std::pair<const Order, const int>> stack;
	int idx;
	bool is_not_doubled;
	void succ();
};
State::State(const std::vector<int> &arg) :state{ arg }, stack{}, idx { 0 }, is_not_doubled{ true } {};
bool State::can_make_seq() const {
	if (idx > 6) {		return false;	}
	else {		return state.at(idx) > 0 && state.at(idx + 1) > 0 && state.at(idx + 2) > 0;	}
}
bool State::can_make_double() const { return idx < 9 && is_not_doubled && state.at(idx) > 1; }
bool State::can_make_triple() const { return idx < 9 && state.at(idx) > 2; }
void State::make_seq() { --state.at(idx); --state.at(idx + 1); --state.at(idx + 2); stack.push(std::make_pair(Order::Seq, idx)); succ(); }
void State::make_double() { state.at(idx) -= 2; stack.push(std::make_pair(Order::Double, idx)); succ(); is_not_doubled = false; }
void State::make_triple() {	state.at(idx) -= 3; stack.push(std::make_pair(Order::Triple, idx)); succ(); }
void State::revert() {
	switch (stack.top().first) {
	case Order::Seq:
		++state.at(stack.top().second); ++state.at(stack.top().second + 1); ++state.at(stack.top().second + 2); idx = stack.top().second;
		break;
	case Order::Double:
		state.at(stack.top().second) += 2; is_not_doubled = true; idx = stack.top().second;
		break;
	case Order::Triple:
		state.at(stack.top().second) += 3; idx = stack.top().second;
		break;
	case Order::Add:
		--state.at(stack.top().second); idx = 0;
	}
	stack.pop();
}
bool State::can_add_one(const int &n) const { return state.at(n - 1) < 4; }
void State::add_one(const int &n) { ++state.at(n - 1); stack.push(std::make_pair(Order::Add, n - 1)); succ(); }
bool State::empty() const { return idx == 9 && !is_not_doubled; }
void State::succ() { while (idx < 9 && state.at(idx) == 0) { ++idx; }; }
bool dp(State &state) {
	if (state.empty()) {
		return true;
	}
	else {
		auto copy = state;
		if (state.can_make_seq()) {
			state.make_seq();
			if (dp(state)) {
				state.revert();
				return true;
			}
			else {
				state.revert();
			}
		}
		if (state.can_make_double()) {
			state.make_double();
			if (dp(state)) {
				state.revert();
				return true;
			}
			else {
				state.revert();
			}
		}
		if (state.can_make_triple()) {
			state.make_triple();
			if (dp(state)) {
				state.revert();
				return true;
			}
			else {
				state.revert();
			}
		}
		return false;
	}
}

std::vector<int> solve(State state) {
	std::vector<int> res;
	const auto copy = state;
	for (auto i = 1; i < 10; ++i) {
		if (state.can_add_one(i)) {
			state.add_one(i);
			if (dp(state)) {
				res.push_back(i);
			}
			state.revert();
		}
	}
	return res;
}
int main() {
	std::string arg;
	while (std::cin >> arg) {
		std::vector<int> vec(9, 0);
		for (const auto &c : arg) {
			++vec.at(c - '1');
		}
		const auto &res = solve(State(vec));
		if (res.size() == 0) {
			std::cout << 0 << std::endl;
		}
		else {
			std::cout << res.at(0);
			for (auto i = 1; i < res.size(); ++i) {
				std::cout << ' ' << res.at(i);
			}
			std::cout << std::endl;
		}
	}
}

Measured memory_bytes: 3172