program abc
	implicit none
	integer :: n,m,l,k,a,b,z
	integer :: si(5)=0,ci(5)=0,x(3)=0
    
	read(*,*) n,m

	a = 10**(n-1)
	b = (10**n) - 1
	z = 0

	do l = a, b
		if(n == 1) then
			x(1) = l
		else if(n == 2) then
			x(2) = mod(l,10)
			x(1) = (l - x(2)) / 10
		else
			x(3) = mod(l,10)
			x(2) = (mod(l,100) - x(3)) / 10
			x(1) = (l - (x(2) * 10 + x(1))) / 100
		endif

		do k = 1, m
			read(*,*) si(m),ci(m)
			if(x(si(m)) /= ci(m)) goto 999
		enddo
		
		z = l
		goto 888
		
999	continue 
	enddo

888	continue
	
	if(z == 0) then
		write(*,*) '-1'
	else
		write(*,*) z
	endif
    
end program abc