
N,M=map(int, input().split())
SC=[list(map(int, input().split())) for _ in range(M)]
for i in range(1000):
	count=0
	for sc in SC:
		s,c=sc[0],sc[1]
		if s==1 and i//(100)==c and c!=0:
			count+=1
		if s==2 and len(str(i))==2:
			if int(str(i)[0])==c and c!=0:
				count+=1
		if s==2 and len(str(i))==3:
			if int(str(i)[1])==c:
				count+=1
		if s==3 and i%10==c:
			count+=1
		else:
			continue
	#print(i,count)
	if count==len(SC):
		print(i)
		exit()

print(-1)

