#-(or child-sbcl swank)
(quit
 :unix-status
 (process-exit-code
  (run-program *runtime-pathname*
               '("--control-stack-size" "64MB"
                 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                 "--eval" "(push :child-sbcl *features*)"
                 "--script" #.(namestring *load-pathname*))
               :output t :error t :input t)))

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS

;; -*- coding:utf-8 -*-
(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\Space))
  "Note that the returned string will be reused."
  (let ((buffer (gensym))
        (character (gensym))
        (idx (gensym)))
    `(let ((,buffer (load-time-value (make-string ,buffer-size
                                                  :element-type 'base-char))))
       (declare (simple-base-string ,buffer))
       (loop for ,character of-type base-char =
                #-swank (code-char (read-byte ,in nil #.(char-code #\Newline)))
                #+swank (read-char ,in nil #\Newline)
             for ,idx from 0
             until (char= ,character #\Newline)
             do (setf (schar ,buffer ,idx) ,character)
             finally (setf (schar ,buffer ,idx) ,terminate-char)
                     (return (values ,buffer ,idx))))))

(defmacro split-ints-bind (vars string &body body)
  (let ((position (gensym))
        (s (gensym)))
    (labels ((expand (vars &optional init-pos)
               (if (null vars)
                   body
                   `((multiple-value-bind (,(car vars) ,position)
                         (parse-integer ,s :start ,(or init-pos position)
                                           :junk-allowed t)
                       ,@(when (null (cdr vars)) `((declare (ignore ,position))))
                       ,@(expand (cdr vars)))))))
      `(let ((,s ,string))
         (declare (string ,s))
         ,@(expand vars 0)))))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil
(defun solve (graph root)
  (declare #.OPT)
  (let* ((n (length graph))
         (cost-table (make-array n :element-type 'uint32 :initial-element 0))
         (parents-table (make-array n :element-type 'int32 :initial-element -1)))
    (setf (aref cost-table root) 0)
    (dotimes (i n)
      (nlet recurse ((graph graph))
        (unless (null graph)
          (let* ((pair (car graph))
                 (a (car pair))
                 (b (cdr pair)))
            (when (> (+ (aref cost-table a) 1) (aref cost-table b))
              (setf (aref cost-table b) (+ (aref cost-table a) 1))
              (setf (aref parents-table b) a))
            (recurse (cdr graph))))))
    parents-table))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (m (read))
         (graph (make-array n :element-type 'list :initial-element nil))
         (rev-graph (make-array n :element-type 'list :initial-element nil))
         (marked (make-array n :element-type 'boolean :initial-element nil))
         sorted
         (out (make-string-output-stream :element-type 'base-char)))
    (declare (uint32 n m))
    (dotimes (i (+ n -1 m))
      (split-ints-bind (a b) (buffered-read-line 20)
        (declare (uint32 a b))
        (push (- b 1) (aref graph (- a 1)))
        (push (- a 1) (aref rev-graph (- b 1)))))
    (dotimes (src n)
      (nlet recurse ((node src))
        (unless (aref marked node)
          (setf (aref marked node) t)
          (dolist (next (aref graph node))
            (recurse next))
          (push node sorted))))
    (let ((rev-sorted (make-array n :element-type 'uint32)))
      (loop for node in sorted
            for idx below n
            do (setf (aref rev-sorted node) idx))
      (dotimes (i n (write-string (get-output-stream-string out)))
        (if (null (aref rev-graph i))
            (println 0 out)
            (println (1+ (the uint32
                              (reduce (lambda (x y)
                                        (if (< (aref rev-sorted x)
                                               (aref rev-sorted y))
                                            y x))
                                      (aref rev-graph i))))
                     out))))))

#-swank(main)


Measured memory_bytes: 42548