def calc_hist(array)
  hist = Array.new(10){ 0 }
  array.each{|v|
    hist[v.to_i] += 1
  }
  return hist
end

#
# ??????????????????????????\????????? true
#
def too_many_pai(hist)
  hist.each{|v|
    return true if v > 4
  }
  return false
end

def is_agari(hist, not_yet_atama)
  delete_zero = hist.dup.delete_if{|v| v == 0}
  return true if delete_zero.empty?
  cur_pai = hist.find_index(delete_zero[0])
  
  # ????
  if not_yet_atama && hist[cur_pai] >= 2
    hist[cur_pai] -= 2
    result = is_agari(hist, false)
    return true if result == true
    hist[cur_pai] += 2
  end

  # ???????
  if hist[cur_pai] >= 3
    hist[cur_pai] -= 3
    result = is_agari(hist, not_yet_atama)
    return true if result == true
    hist[cur_pai] += 3
  end

  # ???????
  if cur_pai <= 7 && hist[cur_pai+1] > 0 && hist[cur_pai+2] > 0 
    hist[cur_pai  ] -= 1
    hist[cur_pai+1] -= 1
    hist[cur_pai+2] -= 1
    result = is_agari(hist, not_yet_atama)
    return true if result == true
    hist[cur_pai  ] += 1
    hist[cur_pai+1] += 1
    hist[cur_pai+2] += 1
  end

  return false

end

ARGF.each{|line|
  pai = line.chomp.split(//).map{|c| c.to_i}
  hist = calc_hist(pai)

  # p pai
  # p hist

  ans = []
  (1..9).each{|c|
    hist2 = hist.dup
    hist2[c] += 1

    next if too_many_pai(hist2)

    not_yet_atama = true
    if is_agari(hist2, not_yet_atama)
      ans << c
    end
  }
  if ans.empty?
    puts "0"
  else
    puts ans.join(' ')
  end
}