import java.io.*; import java.util.*; public class Main_yukicoder832 { private static Scanner sc; private static Printer pr; private static void solve() { char[] s = sc.next().toCharArray(); int[] cnt = new int[9]; for (char c : s) { cnt[c - '1']++; } for (int i = 0; i < 9; i++) { if (cnt[i] == 4) { continue; } int[] tmp = Arrays.copyOf(cnt, cnt.length); tmp[i]++; if (isOK(tmp)) { pr.println(i + 1); } } } private static boolean isOK(int[] cnt) { // chitoi boolean chitoi = true; for (int e : cnt) { if (e != 2 && e != 0) { chitoi = false; break; } } if (chitoi) { return true; } for (int a = 0; a < 9; a++) { if (cnt[a] < 2) { continue; } int[] tmp = Arrays.copyOf(cnt, cnt.length); tmp[a] -= 2; if (isOK2(tmp)) { return true; } } return false; } private static boolean isOK2(int[] cnt) { Deque> st = new ArrayDeque<>(); st.push(new ArrayList<>()); while (!st.isEmpty()) { List list = st.pop(); if (list.size() == 4) { if (isOK3(list, cnt)) { return true; } } else { int s; if (list.size() == 0) { s = 0; } else { s = list.get(list.size() - 1) + 1; } for (int i = s; i < men.length; i++) { if (isOK3(list, cnt)) { List tmp = new ArrayList<>(list); tmp.add(i); st.push(tmp); } } } } return false; } private static boolean isOK3(List list, int[] cnt) { int[] tmp = new int[9]; for (int e : list) { for (int i = 0; i < 9; i++) { tmp[i] += men[e][i]; } } for (int i = 0; i < 9; i++) { if (tmp[i] > cnt[i]) { return false; } } return true; } private static int[][] men = { {3, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 3, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 3, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 3, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 3, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 3, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 3, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 3, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 3}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, }; // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }