// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();
  
function main(){
  for(var i = 0, len = input.length; i < len; i++){
    var c = input[i].split('');
     
    var count = [0,0,0,0,0,0,0,0,0,0,0];
    for(var j = 0, jlen = c.length; j < jlen; j++){
      count[c[j]]++; // 入力の個数をカウント
    }
 
    var result = [];
  JLOOP:for(var j = 1; j <= 9; j++){
      // 引く牌のループ
 
      if(count[j] == 4 || (!count[j-1] && !count[j] && !count[j+1])){
        continue;
      }
     
      for(var k = 1; k <= 9; k++){
        if((j != k && count[k] <= 1) || (j == k && count[k] == 0))
          continue;
 
        var copiedCount = count.slice(0);
        copiedCount[j]++;
        copiedCount[k] -= 2;

        for(var l = 1; l <= 9; l++){
          if(copiedCount[l-1] >= 1 && copiedCount[l] >= 1 && copiedCount[l+1] >= 1){
            copiedCount[l-1]--;
            copiedCount[l]--;
            copiedCount[l+1]--;
          }
          if(copiedCount[l-1] >= 1 && copiedCount[l] >= 1 && copiedCount[l+1] >= 1){
            copiedCount[l-1]--;
            copiedCount[l]--;
            copiedCount[l+1]--;
          }
          if(copiedCount[l] >= 3){
            copiedCount[l] -= 3;
          }
        }
        var sum = 0;
        for(var l = 1; l <=9; l++){
          sum += copiedCount[l];
        }
 
        if(!sum){
          result.push(j);
          continue JLOOP;
        }
      }
    }
 
    console.log(result.length?result.join(' '):'0');
     
 
  }
   
}