import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val seq1 = for(i<-1 to 9) yield List(i,i,i)
  val seq2 = (1 to 9).iterator.sliding(3).toList

  def check(m:List[Int], count:Int,u:Int):Boolean =  {
    if(m.length != count) false
    else if(count==2) { if(m.head==m.last) true else false }
    else {
      if((u to 8).exists( i=> check(m diff seq1(i),count-3,i) )) true
      else (0 to 6).exists(i=> check(m diff seq2(i),count-3,u))
    }
  }

  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) }
    if(m.length>0) println(m.mkString(" ")) else println(0)
  }
}