using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var s = ReadLine(); var count = new int[9]; foreach (var c in s) ++count[c - '1']; for (var i = 0; i < 9; ++i) { if (count[i] == 4) continue; var ncount = (int[]) count.Clone(); ++ncount[i]; if (Judge(ncount)) WriteLine(i + 1); } } static bool Judge(int[] count) { if (Judge2(count, true)) return true; for (var i = 0; i < 7; ++i) { --count[i]; --count[i + 1]; --count[i + 2]; if (Judge2(count, false)) return true; for (var j = i; j < 7; ++j) { --count[j]; --count[j + 1]; --count[j + 2]; if (Judge2(count, false)) return true; for (var k = j; k < 7; ++k) { --count[k]; --count[k + 1]; --count[k + 2]; if (Judge2(count, false)) return true; for (var l = k; l < 7; ++l) { --count[l]; --count[l + 1]; --count[l + 2]; if (Judge2(count, false)) return true; ++count[l]; ++count[l + 1]; ++count[l + 2]; } ++count[k]; ++count[k + 1]; ++count[k + 2]; } ++count[j]; ++count[j + 1]; ++count[j + 2]; } ++count[i]; ++count[i + 1]; ++count[i + 2]; } return false; } static bool Judge2(int[] count, bool isAll) { if (count.Any(ci => ci < 0)) return false; var two = 0; var three = 0; var other = 0; foreach (var ci in count) { if (ci == 2) ++two; else if (ci == 3) ++three; else if (ci > 0) ++other; } if (other > 0) return false; if (isAll && two == 7) return true; if (two == 1) return true; return false; } }