n,m=map(int,input().split())
L=[10]*3
for i in range(m):
	s,c=map(int,input().split())
	if L[s-1]==10 or L[s-1]==c:
		L[s-1]=c
	else:
		print(-1)
		exit()
if n==1:
	if L[0]==10:
		print(0)
		exit()
	else:
		print(L[0])
		exit()
else:
	if L[0]==10:
		L[0]=1
	elif L[0]==0:
		print(-1)
		exit()
	else:
		for i in range(1,n):
			if L[i]==10:
				L[i]=0
	print(''.join(map(str,L)))