;; C - Guess The Number

(defun solve (n sc)
  (loop for i from 0 below (expt 10 n)
        for digits = (map 'array #'digit-char-p (princ-to-string i))
     when (and (= (length digits) n)
               (zerop
                 (loop for (s . c) in sc
                   count (not (eql c (aref digits (1- s)))))))
     do (return i)
     finally (return -1)))

(let* ((n  (read))
       (m  (read))
       (sc (loop repeat m collect (cons (read) (read)))))
  (princ (solve n sc)))
