#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> a(14);
bool solve(int x, int y);
int main(){
  string s;
  while(cin >>s){
    vector<int> ans;
    for(int i=1; i<10; i++){
      int n[10]={};
      bool f = true;
      for(int j=0; j<s.size(); j++) a[j] = s[j]-'0';
      a[13] = i;
      sort(a.begin(),a.end());
      for(int j=0; j<a.size(); j++) n[a[j]]++;
      for(int j=1; j<10; j++) if(n[j]>4) f = false;
      if(f) if(solve(1,4)) ans.push_back(i);
    }
    if(ans.size() == 0) cout <<"0"<<endl;
    else{
      for(int i=0; i<ans.size(); i++){
	if(i != 0) cout <<" ";
	cout <<ans[i];
      }
      cout <<endl;
    }
  }
}
bool solve(int x, int y){
  int ans = false;
  if(x == 0 && y == 0) return true;
  if(x == 1){
    for(int i=0; i<13; i++){
      if(a[i] == -1) continue;
      if(a[i] == a[i+1]){
	int sc = a[i];
	a[i] = a[i+1] = -1;
	ans = ans|solve(0,y);
	a[i] = a[i+1] = sc;
      }
    }
  }
  if(y != 0){
    for(int i=0; i<12; i++){
      if(a[i] == -1) continue;
      if(a[i] == a[i+1] && a[i+1] == a[i+2]){
	int sc = a[i];
	a[i] = a[i+1] = a[i+2] = -1;
	ans = ans|solve(x,y-1);
	a[i] = a[i+1] = a[i+2] = sc;
      }
      for(int j=i+1; j<13; j++){
	if(a[j]!=a[i]+1) continue;
	for(int k=j+1; k<14; k++){
	  if(a[k]!=a[j]+1) continue;
	  int sc = a[i];
	  a[i] = a[j] = a[k] = -1;
	  ans = ans|solve(x,y-1);
	  a[i] = sc; a[j] = sc+1; a[k] = sc+2;
	}
      }
    }
  }
  return ans;
}