(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setq minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

;;;
;;; Complement to the bitwise operations in CLHS
;;;

(eval-when (:compile-toplevel :load-toplevel :execute)
  (assert (= sb-vm:n-word-bits 64)))

;; KLUDGE: a variant of DPB that handles a 64-bit word efficiently
(defmacro u64-dpb (new spec int)
  (destructuring-bind (byte s p) spec
    (assert (eql 'byte byte))
    (let ((size (gensym)) (posn (gensym)) (mask (gensym)))
      `(let* ((,size ,s)
              (,posn ,p)
              (,mask (ldb (byte ,size 0) -1)))
         (logior (the (unsigned-byte 64) (ash (logand ,new ,mask) ,posn))
                 (the (unsigned-byte 64) (logand ,int (lognot (ash ,mask ,posn)))))))))

(defconstant +most-positive-word+ #.(- (ash 1 64) 1))

;; TODO: right shift
(defun bit-lshift (bit-vector delta &optional result-vector end)
  "Left-shifts BIT-VECTOR by DELTA bits and fills the new bits with zero.
The behaviour is the same as the bit-wise operations in CLHS: The result is
copied to RESULT-VECTOR; if it is T, BIT-VECTOR is destructively modified; if it
is NIL, a new bit-vector of the same length is created. If END is specified,
this function shifts only the range [0, END) of BIT-VECTOR and copies it to the
range [0, END+DELTA) of RESULT-VECTOR.

Note that here `left' means the direction from a smaller index to a larger one,
i.e. (bit-lshift #*1011000 2) |-> #*0010110"
  (declare (optimize (speed 3))
           (simple-bit-vector bit-vector)
           ((or null (eql t) simple-bit-vector) result-vector)
           ((integer 0 #.most-positive-fixnum) delta)
           ((or null (integer 0 #.most-positive-fixnum)) end))
  (setq result-vector
        (etypecase result-vector
          (null (make-array (length bit-vector) :element-type 'bit :initial-element 0))
          ((eql t) bit-vector)
          (simple-bit-vector result-vector)))
  (setq end (or end (length bit-vector)))
  (assert (<= end (length bit-vector)))
  (setq end (min end (max 0 (- (length result-vector) delta))))
  (multiple-value-bind (d/64 d%64) (floor delta 64)
    (declare (optimize (safety 0))
             (simple-bit-vector result-vector))
    (multiple-value-bind (end/64 end%64) (floor end 64)
      ;; process the last word separately
      (unless (zerop end%64)
        (let ((word (sb-kernel:%vector-raw-bits bit-vector end/64)))
          (setf (sb-kernel:%vector-raw-bits result-vector (+ end/64 d/64))
                (u64-dpb word
                         (byte (min end%64 (- 64 d%64)) d%64)
                         (sb-kernel:%vector-raw-bits result-vector (+ end/64 d/64))))
          (when (> end%64 (- 64 d%64))
            (setf (ldb (byte (- end%64 (- 64 d%64)) 0)
                       (sb-kernel:%vector-raw-bits result-vector (+ 1 end/64 d/64)))
                  (ldb (byte (- end%64 (- 64 d%64)) (- 64 d%64)) word)))))
      ;; Body. We avoid LDB and DPB here for efficiency, though this seems to
      ;; be somewhat incomprehensible...
      (let* ((mask0 (ldb (byte 64 0) (lognot (ldb (byte d%64 0) -1))))
             (mask1-lo (ldb (byte (- 64 d%64) 0) -1))
             (mask1-hi (ldb (byte 64 0) (lognot (ash mask1-lo d%64)))))
        (declare ((unsigned-byte 64) mask0 mask1-lo mask1-hi))
        (do ((i (- end/64 1) (- i 1)))
            ((< i 0))
          (let ((word (sb-kernel:%vector-raw-bits bit-vector i))
                (i+d/64 (+ i d/64)))
            (declare ((unsigned-byte 64) word)
                     ((mod #.most-positive-fixnum) i+d/64))
            (setf (sb-kernel:%vector-raw-bits result-vector i+d/64)
                  (logior (the (unsigned-byte 64)
                               (ash (logand word mask1-lo) d%64))
                          (logand (sb-kernel:%vector-raw-bits result-vector i+d/64)
                                  mask1-hi)))
            (setf (sb-kernel:%vector-raw-bits result-vector (+ 1 i+d/64))
                  (logior (ash word (- d%64 64))
                          (logand (sb-kernel:%vector-raw-bits result-vector (+ 1 i+d/64))
                                  mask0))))))
      ;; zero padding
      (when (< d/64 (ceiling (length result-vector) 64))
        (setf (ldb (byte d%64 0) (sb-kernel:%vector-raw-bits result-vector d/64)) 0))
      ;; REVIEW: May we set the last word of a bit vector to zero beyond the
      ;; actual bound?
      (dotimes (i (min d/64 (ceiling (length result-vector) 64)))
        (setf (sb-kernel:%vector-raw-bits result-vector i) 0))
      result-vector)))

;; PAY ATTENTION TO THE STACK SIZE!
(declaim (ftype (function * (values (or null simple-bit-vector) &optional)) bipartite-p))
(defun bipartite-p (graph)
  "Checks if GRAPH is bipartite and returns the vector of colorings if so,
otherwise returns NIL. GRAPH must be a vector of adjacency lists."
  (declare #.OPT
           ((simple-array list (*)) graph))
  (let* ((n (length graph))
         (visited (make-array n :element-type 'bit :initial-element 0))
         (colors (make-array n :element-type 'bit :initial-element 0)))
    (labels ((dfs (vertex color)
               (cond ((zerop (aref visited vertex))
                      (setf (aref visited vertex) 1
                            (aref colors vertex) color)
                      (if (= color 1)
                          (dolist (neighbor (aref graph vertex))
                            (dfs neighbor 0))
                          (dolist (neighbor (aref graph vertex))
                            (dfs neighbor 1))))
                     ((/= color (aref colors vertex))
                      (return-from bipartite-p nil)))))
      (dotimes (i n colors)
        (when (zerop (aref visited i))
          (dfs i 1))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(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)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (m (read))
         (mat (make-array (list n n) :element-type 'bit :initial-element 0))
         (graph (make-array n :element-type 'list :initial-element nil)))
    (declare (uint31 n m))
    (dotimes (i m)
      (let ((a (- (read) 1))
            (b (- (read) 1)))
        (setf (aref mat a b) 1
              (aref mat b a) 1)))
    (dotimes (i n)
      (dotimes (j n)
        (when (and (/= i j) (zerop (aref mat i j)))
          (push j (aref graph i)))))
    (let ((colorings (bipartite-p graph))
          (visited (make-array n :element-type 'bit :initial-element 0))
          (dp (make-array 701 :element-type 'bit :initial-element 0))
          (tmp0 (make-array 701 :element-type 'bit :initial-element 0))
          (tmp1 (make-array 701 :element-type 'bit :initial-element 0)))
      (unless colorings
        (println -1)
        (return-from main))
      (setf (aref dp 0) 1)
      (labels ((dfs (v)
                 (setf (aref visited v) 1)
                 (let ((sum0 (if (= 0 (aref colorings v)) 1 0))
                       (sum1 (if (= 1 (aref colorings v)) 1 0)))
                   (declare (uint31 sum0 sum1))
                   (dolist (neighbor (aref graph v))
                     (when (zerop (aref visited neighbor))
                       (multiple-value-bind (delta0 delta1) (dfs neighbor)
                         (incf sum0 delta0)
                         (incf sum1 delta1))))
                   (values sum0 sum1))))
        (dotimes (v n)
          (when (zerop (aref visited v))
            (multiple-value-bind (size0 size1) (dfs v)
              (bit-lshift dp size0 tmp0)
              (bit-lshift dp size1 tmp1)
              (bit-ior tmp0 tmp1 dp))))
        (loop for size1 from (floor n 2) downto 0
              do (when (= 1 (aref dp size1))
                   (let ((size2 (- n size1)))
                     (println (+ (ash (* size1 (- size1 1)) -1)
                                 (ash (* size2 (- size2 1)) -1)))
                     (return-from main))))
        (error "Huh?")))))

#-swank (main)

;;;
;;; Test and benchmark
;;;

#+swank
(defun io-equal (in-string out-string &key (function #'main) (test #'equal))
  "Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if
the string output to *STANDARD-OUTPUT* is equal to OUT-STRING."
  (labels ((ensure-last-lf (s)
             (if (eql (uiop:last-char s) #\Linefeed)
                 s
                 (uiop:strcat s uiop:+lf+))))
    (funcall test
             (ensure-last-lf out-string)
             (with-output-to-string (out)
               (let ((*standard-output* out))
                 (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                   (funcall function)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  "THING := null | string | symbol | pathname

null: run #'MAIN using the text on clipboard as input.
string: run #'MAIN using the string as input.
symbol: alias of FIVEAM:RUN!.
pathname: run #'MAIN using the text file as input."
  (let ((*standard-output* out))
    (etypecase thing
      (null
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname
       (with-open-file (*standard-input* thing)
         (main))))))

#+swank
(defun gen-dat ()
  (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
    (format out "")))

#+swank
(defun bench (&optional (out (make-broadcast-stream)))
  (time (run *dat-pathname* out)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "5 5
1 2
1 3
3 4
3 5
4 5
"
    "4
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "5 1
1 2
"
    "-1
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4 3
1 2
1 3
2 3
"
    "3
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 39
7 2
7 1
5 6
5 8
9 10
2 8
8 7
3 10
10 1
8 10
2 3
7 4
3 9
4 10
3 4
6 1
6 7
9 5
9 7
6 9
9 4
4 6
7 5
8 3
2 5
9 2
10 7
8 6
8 9
7 3
5 3
4 5
6 3
2 10
5 10
4 2
6 2
8 4
10 6
"
    "21
")))


Measured memory_bytes: 61792