#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

bool search(vector<int> tehai) {
  sort(tehai.begin(), tehai.end());
  /*for (int i = 0; i < tehai.size(); i++) {
    printf("%d", tehai[i]);
    }
    printf("\n");*/
  for (int i = 0; i < tehai.size() - 2; i++) {
    if ((tehai[i] == tehai[i + 1] && tehai[i] == tehai[i + 2])) {
      vector<int> _tehai = tehai;
      _tehai.erase(_tehai.begin() + i, _tehai.begin() + (i + 3));
      /*printf("\t");
	for (int j = 0; j < _tehai.size(); j++) {
	printf("%d", _tehai[j]);
	}
	printf("\n");*/
      if (_tehai.empty()) {
	return true;
      }
      if(search(_tehai)) {
	return true;
      }
    }
  }
  for (int i = 0; i < tehai.size() - 1; i++) {
    if (tehai[i + 1] == tehai[i] + 1) {
      for (int j = i + 2; j < tehai.size(); j++) {
	if (tehai[j] == tehai[i] + 2) {
	  vector<int> _tehai = tehai;
	  _tehai.erase(_tehai.begin() + i, _tehai.begin() + i + 2);
	  _tehai.erase(_tehai.begin() + (j - 2));
	  if (_tehai.empty()) {
	    return true;
	  }
	  if (search(_tehai)) {
	    return true;
	  }
	}
      }
    }
  }
  return false;
}

int main()
{
  vector<int> tehai(13);
  while (scanf("%1d ", &tehai[0]) == 1) {
    set<int> result, full;
    for (int i = 1; i < 13; i++) {
      scanf("%1d ", &tehai[i]);
    }
    sort(tehai.begin(), tehai.end());
    for (int i = 0; i < tehai.size() - 3; i++) {
      if (tehai[i] == tehai[i + 1] && tehai[i] == tehai[i + 2] && tehai[i] == tehai[i + 3]) {
	full.insert(tehai[i]);
      }
    }
    for (int i = 1; i <= 9; i++) {
      if (full.find(i) != full.end()) {
	continue;
      }
      vector<int> _tehai = tehai;
      _tehai.push_back(i);
      sort(_tehai.begin(), _tehai.end());
      for (int j = 0; j < _tehai.size(); j++) {
	if (_tehai[j + 1] == _tehai[j]) {
	  vector<int> __tehai = _tehai;
	  __tehai.erase(__tehai.begin() + j, __tehai.begin() + (j + 1) + 1);
	  if (search(__tehai)) {
	    result.insert(i);
	    goto next;
	  }
	}
      }
    next:;
    }

    for (set<int>::iterator it = result.begin(); it != result.end(); it++) {
      printf("%d ", *it);
    }
    if (result.empty()) {
      printf("0");
    }
    printf("\n");
  }
  return 0;
}