;vector
(define(mv n)(make-vector n 0))(define(vr v k)(vector-ref v k))(define(vs! v k a)(vector-set! v k a))
(define(vi! v k)(vector-set! v k(+(vector-ref v k)1)))(define(vd! v k)(vector-set! v k(-(vector-ref v k)1)))
(define(vvr v y x X)(vector-ref v(+(* y X)x)))(define(vvs! v y x X a)(vector-set! v(+(* y X)x)a))
(define(vswap! v i j)(let((t(vector-ref v i)))(vector-set! v i(vector-ref v j))(vector-set! v j t)))
(define(vector=? a b)(let((n(vector-length a))(nb(vector-length b))(f #t))(if(= n nb)(begin(dotimes(i n)(unless(=(vector-ref a i)(vector-ref b i))(set! f #f)))f)#f)))
;string
(define(xs x)(x->string x))(define(sr s i)(string-ref s i))(define(ss! s i c)(string-set! s i c))(define(sl s)(string-length s))
(define(subst s l r)(substring s l r))(define(ssl s c)(string-scan s c))(define(ssr s c)(string-scan-right s c))
;tree-map
(define(mktm a b)(make-tree-map a b));(mktm = <)
(define(tmpt! t k v)(tree-map-put! t k v))(define(tmgt t k)(tree-map-get t k 0))(define(tmdl! t k)(tree-map-delete! t k))
(define(tmex? t k)(tree-map-exists? t k))(define(tmfl? t)(not(tree-map-empty? t)))(define(tmne t)(tree-map-num-entries t))
(define(tmmi t)(tree-map-min t))(define(tmma t)(tree-map-max t))(define(tmpmi! t)(tree-map-pop-min! t))(define(tmpma! t)(tree-map-pop-max! t))
;pair
(define(mp a b)(logxor(ash a 17)b))(define(fi p)(ash p -17))(define(se p)(logand p 131071))
(define(cmp a b)(if(<(se a)(se b))#t #f));(sort pairs cmp)
;other
(define(lsb n)(-(integer-length(logxor(- n 1)n))1))(define(fact n)(if(= n 1)1(*(fact(- n 1))n)))(define(inex x)(exact->inexact x))
(define(prime? a)(cond((< a 2)#f)((= a 2)#t)((even? a)#f)(else(let((n(sqrt a)))(let f((i 3))(if(<= i n)(if(=(mod a i)0)#f(f(+ i 2)))#t))))))
(define(read-vector a)(dotimes(i(vector-length a))(vector-set! a i(read))))
(define(read-vector-of-string a)(dotimes(i(vector-length a))(vector-set! a i(xs(read)))))
(define(nextpermutation! a)
	(let*((n(vector-length a))(i(- n 2))(j(- n 1))(t 1))
		(if(sorted? a <)
			(dotimes(k n)(vector-set! a k(+ k 1)));#(3 2 1)->#(1 2 3)
			(begin
	  			(while(>(vector-ref a i)(vector-ref a(+ i 1)))(dec! i))
				(while(>(vector-ref a i)(vector-ref a j))(dec! j))
				(vswap! a i j)
				(while(<=(+ i t)(- n t))(vswap! a(+ i t)(- n t))(inc! t))))))

(define n(read))
(define a(make-vector n -1))
(define m(read))
(define s 0)
(define c 0)
(dotimes(i m)
	(set! s(-(read)1))
	(set! c(read))
	(if(or(=(vr a s)-1)(=(vr a s)c))
		(vs! a s c)
		(begin(print -1)(exit))
	)
)
(when(= n 1)(print(max(vr a 0)0))(exit))
(when(=(vr a 0)0)(print -1)(exit))
(display(max(vr a(- n 1))1))
(dotimes(i(- n 1))(display(max(vr a(+ i 1))0)))
