#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 = 0; i < tehai.size(); i++) {
      printf("%d", tehai[i]);
      }
      printf("\n");*/
    for (int i = 0; i < tehai.size(); i++) {
      if (full.find(tehai[i]) == full.end()) {
	vector<int> tanki = tehai;
	tanki.erase(tanki.begin() + i);
	if (search(tanki)) {
	  /*for (int j = 0; j < tanki.size(); j++) {
	    printf("%d", tanki[j]);
	  }
	  printf(":a = %d\n", tehai[i]);*/
	  result.insert(tehai[i]);
	}
      }
    }
    for (int i = 0; i < tehai.size() - 1; i++) {
      if (tehai[i] == tehai[i + 1]) {
	vector<int> _tehai = tehai;
	_tehai.erase(_tehai.begin() + i, _tehai.begin() + (i + 2));
	/*for (int j = 0; j < _tehai.size(); j++) {
	  printf("%d", _tehai[j]);
	  }
	  printf("\n");*/
	for (int j = 0; j < _tehai.size() - 1; j++) {
	  if (_tehai[j] == _tehai[j + 1] || _tehai[j + 1] == _tehai[j] + 1 || _tehai[j + 1] == tehai[j] + 2) {
	    int a = _tehai[j], b = _tehai[j + 1];
	    vector<int> __tehai = _tehai;
	    __tehai.erase(__tehai.begin() + j, __tehai.begin() + (j + 2));
	    /*for (int k = 0; k < __tehai.size(); k++) {
	      printf("%d", __tehai[k]);
	      }
	      printf("\n");*/
	
	    if (search(__tehai)) {
	      /*for (int k = 0; k < __tehai.size(); k++) {
		printf("%d", __tehai[k]);
		}
		printf(":a, b = %d, %d\n", a, b);*/
	      if (a == b && full.find(a) == full.end()) {
		//printf("inserted:%d\n", a);
		result.insert(a);
	      } else {
		if (abs(a - b) == 1 && full.find(min(a, b) - 1) == full.end() && min(a, b) - 1 >= 1) {
		  //printf("inserted:%d\n", min(a, b) - 1);
		  result.insert(min(a, b) - 1);
		} if (abs(a - b) == 1 && full.find(max(a, b) + 1) == full.end() && max(a, b) + 1 <= 9) {
		  //printf("inserted:%d\n", max(a, b) + 1);
		  result.insert(max(a, b) + 1);
		}
		if(abs(a - b) == 2 && full.find(min(a, b) + 1) == full.end()) {
		  result.insert(min(a, b) + 1);
		}
	      }
	    }
	  }
	}
      }
    }
    for (set<int>::iterator it = result.begin(); it != result.end(); it++) {
      printf("%d ", *it);
    }
    if (result.empty()) {
      printf("0");
    }
    printf("\n");
  }
  return 0;
}