import scala.io.StdIn.{readLine,readInt}
 
object Main extends App {
  val seq1 = for(i<-1 to 9) yield List(i,i,i)
  val seq2 = for(i<-1 to 7) yield List(i,i+1,i+2)
 
  def check(m:List[Int], count:Int,u:Int,v:Int):Boolean =  {
    if(m.length != count) false
    else if(count==2) {
      val List(x,y) = m
      if(x==y) true else false
    } else {
      if((u to 8).exists( i=> check(m diff seq1(i),count-3,i+1,v))) {
        true
      } else {
        (v to 6).exists(i=> check(m diff seq2(i),count-3,u,i) )
      }
    }
  }
 
  Iterator.continually(readLine).takeWhile ( _!=null ).foreach { line =>
    val l = line.map(_.asDigit).toList
    val m = (1 to 9).filter { i=> if(l.count( _==i ) >= 4) false else check(i::l,14,0,0) }
    if(m.length>0) println(m.mkString(" ")) else println(0)