(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
(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 splitted-integers-bind (vars string &body body)
  (let ((pos1 (gensym))
	(pos2 (gensym))
	(s (gensym)))
    (labels ((expand (vars &optional init-pos1)
	       (if (null vars)
		   body
		   `((let* ((,pos1 ,(or init-pos1 `(1+ ,pos2)))
			    (,pos2 (position #\space ,s :start ,pos1 :test #'char=))
			    (,(car vars) (parse-integer ,s :start ,pos1 :end ,pos2)))
		       ,@(expand (cdr vars)))))))
      `(let ((,s ,string))
         (declare (string ,s))
	 ,@(expand vars 0)))))

(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 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 main ()
  (declare #.OPT)
  (let* ((n (read))
         (m (read))
         seq)
    (declare (uint32 n m)
             (list seq))
    (dotimes (i m)
      (splitted-integers-bind (a b) (buffered-read-line 20)
        (push (cons a b) seq)))
    (setf seq (sort seq #'< :key #'car))
    (nlet rec ((seq seq) (l 0) (r 0) (num 0))
      (declare (uint32 l r num))
      (if (null seq)
          (println num)
          (let* ((query (car seq))
                 (new-l (max l (car query)))
                 (new-r (min r (cdr query))))
            (declare ((cons uint32 uint32) query))
            (if (< new-l new-r)
                (rec (cdr seq) new-l new-r num)
                (rec (cdr seq) (car query) (cdr query) (1+ num))))))))

#-swank(main)


Measured memory_bytes: 23520