using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Three = new List<int[]>();
		for(int i=1;i<=7;i++){
			for(int j=0;j<3;j++){
				Three.Add(new int[]{i,i+1,i+2});
			}
		}
		for(int i=1;i<=9;i++){
			Three.Add(new int[]{i,i,i});
		}
		
		int[] cnt = new int[10];
		for(int i=0;i<S.Length;i++) cnt[S[i] - '0']++;
		
		List<int> ans = new List<int>();
		for(int i=1;i<=9;i++){
			
			cnt[i]++;
			
			bool chk2 = true;
			for(int j=1;j<=9;j++) chk2 &= (cnt[j] % 2) == 0 && cnt[j] != 4;
			if(chk2){
//Console.WriteLine("chk2: i:{0}",i);
				ans.Add(i);
				cnt[i]--;
				continue;
			}
			
			bool chk3 = false;
			for(int a=0;a<Three.Count;a++){
				if(chk3) break;
				for(int b=a+1;b<Three.Count;b++){
					if(chk3) break;
					for(int c=b+1;c<Three.Count;c++){
						if(chk3) break;
						for(int d=c+1;d<Three.Count;d++){
							if(chk3) break;
							
							int[] c0 = new int[10];
							for(int j=0;j<3;j++){
								c0[Three[a][j]]++;
								c0[Three[b][j]]++;
								c0[Three[c][j]]++;
								c0[Three[d][j]]++;
							}
							
							bool chk = true;
							int[] diff = new int[10];
							for(int j=1;j<10;j++){
								if(cnt[j] > 4) chk = false;
								diff[j] = cnt[j] - c0[j];
								if(diff[j] < 0) chk = false;
							}
							if(!chk) continue;
							
							for(int j=1;j<10;j++){
								if(diff[j] == 2) chk3 = true;
							}
/*							if(chk3){
								Console.WriteLine("i:{0}",i);
								Console.WriteLine(String.Join(" ",cnt));
								Console.WriteLine(String.Join(" ",c0));
								Console.WriteLine(String.Join(" ",diff));
							}
*/
						}
					}
				}
			}
			if(chk3){
				ans.Add(i);
			}
			cnt[i]--;
		}
		
		foreach(var n in ans) Console.WriteLine(n);
		
		
		
	}
	
	List<int[]> Three;
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}