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 L[0]==10:
	print(-1)
	exit()
if n!=1 and L[0]==0:
	print(-1)
	exit()
for i in range(n):
	if L[i]==10:
		L[i]=0
print(''.join(map(str,L)))