#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <unordered_map>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

bool check1(vll& hand)
{
    ll count = 0;
    ll max1 = 0;
    for2(i,1,10) {
        count += hand[i];
        max1 = max(max1, hand[i]);
    }
    if (count == 2) {
        if (max1 == 2) {
            return true;
        } else {
            return false;
        }
    }

    bool ret;
    for2(i,1,10) {
        if (hand[i] >= 3) {
            hand[i] -= 3;
            ret = check1(hand);
            hand[i] += 3;
            if (ret) {
                return true;
            }
        }
    }
    for2(i,1,8) {
        if (hand[i] >= 1 && hand[i+1] >= 1 && hand[i+2] >= 1) {
            hand[i] -= 1;
            hand[i+1] -= 1;
            hand[i+2] -= 1;
            ret = check1(hand);
            hand[i] += 1;
            hand[i+1] += 1;
            hand[i+2] += 1;
            if (ret) {
                return true;
            }
        }
    }
    return false;
}

bool check2(vll& hand)
{
    ll ok = 0;
    for2(i,1,10) {
        if (hand[i] == 2) {
            ++ok;
        }
    }
    if (ok == 7) {
        return true;
    }
    return false;
}

void solve()
{
    string S;
    vll hand(10,0);
    cin >> S;
    for (char c : S) {
        hand[c - '0'] += 1;
    }
    for2(i,1,10) {
        //dumplist(hand);
        if (hand[i] <= 3) {
            hand[i] += 1;
            if (check1(hand) || check2(hand)) {
                cout << i << endl;
            }
            hand[i] -= 1;
        }
    }
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}