import sys
input=sys.stdin.readline


def main():
	N,M=map(int,input().split())
	#S=input().rstrip()
	#N=int(input())
	#vA=list(map(int,input().split()))
	vAB=[tuple(map(int,input().split()))
		 for _ in [0,]*M]
	
	vN = [-1,]*N
	for p,q in vAB:
		if vN[p-1]!=-1 and vN[p-1]!= q:
			print(-1)
			return
		vN[p-1] = q
	
	#print(vN)
	for i in range(10**(N-1),10**N):
		s = str(i)
		#print(s)
		ok = True
		for j,sc in enumerate(s):
			if vN[j]!=-1 and vN[j]!=int(sc):
				#print(j,sc)
				ok = False
		
		if ok:
			print(i)
			return
	else:
		print(-1)
	
	
main()
