(defun num-to-char (num)
  (code-char (+ num (char-code #\0))))

(defun solve (n m pairs)
  (let ((num (make-array n :element-type 'character :initial-element #\-)))
    (loop for (s . c) in pairs
          if (char= #\- (aref num (1- s)))
          do (setf (aref num (1- s)) (num-to-char c))
          else if (char/= (aref num (1- s)) (num-to-char c))
          do (return-from solve -1))
    (when (char= (aref num 0) #\-)
      (setf (aref num 0) #\1))
    (loop for i from 0
          for n across num
          if (char= n #\-)
          do (setf (aref num i) #\0))
    (if (and (< 1 n)
             (char= (aref num 0) #\0))
        -1
        (read-from-string num))))

#-swank
(let* ((n (read))
       (m (read))
       (pairs (loop repeat m collect (cons (read) (read)))))
  (format t "~A~%" (solve n m pairs)))
