def reach(arr)
  ans = []
  9.times{|i|
    next if arr[i] == 4
    b = arr.clone
    b[i] += 1
    if is_ron(b)
      ans << i + 1
    end
  }
  return ans
end

def is_ron(b)
  9.times{|i|
    if b[i] > 1
      # candidate of head
      c = b.clone
      c[i] -= 2
      if grouping(c)
        return true
      end
    end
  }
  return false
end

def grouping(c)
  7.times{|i|
    if c[i] == 4
      return false if c[i+1] == 0 || c[i+2] == 0
      c[i] -= 1
      c[i+1] -= 1
      c[i+2] -= 1
    end

    if c[i] == 3
      if c[i+1] < 3 || c[i+2] < 3
        c[i] -= 3
      else
        c[i] -= 1
        c[i+1] -= 1
        c[i+2] -= 1
      end
    end

    if c[i] == 2
      return false if c[i+1] < 2 || c[i+2] < 2
      c[i] -= 2
      c[i+1] -= 2
      c[i+2] -= 2
    end

    if c[i] == 1
      return false if c[i+1] < 1 || c[i+2] < 1
      c[i] -= 1
      c[i+1] -= 1
      c[i+2] -= 1
    end
  }
  return false if c - [0, 3] != []
  return true
end


while input = gets
  arr = Array.new(9){0}
  input.chomp.split("").map(&:to_i).each{|i|
    arr[i-1] += 1
  }
  ans = reach(arr)
  if ans.size > 0
    puts ans.join(" ")
  else
    puts 0
  end
end