N,M=map(int,input().split())
L=[list(map(int,input().split())) for i in range(M)]
ans=float("inf")

if N==1: k=0
elif N==2: k=10
elif N==3: k=100
for i in range(k,1000):
	flg=True
	for a,b in L:
		if list(str(i))[a-1]==str(b):
			continue
		flg=False
	if flg:
		ans=i
		break
if ans==float("inf"): print(-1)
print(ans)

