(let* ((n (read))
       (m (read))
       (lst (loop :repeat m :collect (cons (1- (read)) (read-char)))))
  (loop :for k :from (expt 10 (1- n)) :upto (1- (expt 10 n))
        :if (loop :for (x . y) :in lst
                  :with j = (format nil "~A" k)
                  :always (char= y (aref j x)))
          :do (progn (princ k) (return))
          :finally (princ -1)))