#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
template<class T, class U> T lexical_cast(const U& from)
{ T to; stringstream ss; ss << from; ss >> to; return to; }
template<class T> void pv(T a,T b)
{ for(T it = a; it != b; ++it) cerr << *it << '_'; cerr << endl; }
const int INF = (int)1e9;
const double PI = M_PI, EPS = 1e-8;
typedef long long int lli;

bool solve(vector<int> &v, int ok) {
    if(ok >= 4) return true;
    bool valid = false;
    for(int i = 1; i <= 9; i++) {
        if(v[i] >= 3) {
            v[i] -= 3;
            valid = valid || solve(v, ok + 1);
            v[i] += 3;
        }
    }
    for(int i = 1; i <= 7; i++) {
        if(v[i] >= 1 && v[i + 1] >= 1 && v[i + 2] >= 1) {
            v[i]--, v[i + 1]--, v[i + 2]--;
            valid = valid || solve(v, ok + 1);
            v[i]++, v[i + 1]++, v[i + 2]++;
        }
    }
    return valid;
}

int main() {
    string line;
    while(getline(cin, line)) {
        vector<int> counter(10, 0);
        for(char c : line) {
            int i = c - '0';
            counter[i]++;
        }

        vector<int> ans;

        for(int add = 1; add <= 9; add++) {
            counter[add]++;

            bool over = false;
            vector<int> two;
            for(int i = 1; i <= 9; i++) {
                if(counter[i] > 4) over = true;
                if(counter[i] >= 2) two.push_back(i);
            }

            bool valid = false;

            if(over == false) {
                for(int t : two) {
                    counter[t] -= 2;
                    valid = valid || solve(counter, 0);
                    counter[t] += 2;
                }
            }

            if(valid) ans.push_back(add);

            counter[add]--;
        }

        if(ans.size() == 0) cout << 0 << endl;
        else {
            for(int i = 0; i < (int)ans.size() - 1; i++) {
                cout << ans[i] << ' ';
            }
            cout << *ans.rbegin() << endl;
        }
    }
}