N, M = map(int, input().split())
sc = [list(map(int, input().split()))for i in range(M)]
ans="-1"
tmp=0
for i in range(0,1000):
	s = str('{:0=3}'.format(i))
	for j in range(M):
		if sc[j][0]==1 and sc[j][1] == 0:
			print(-1)
			exit()
		if s[len(s)-N+sc[j][0]-1]!=str(sc[j][1]):
			break
	else:
		if s[0]=="0":
			s=str(int(s)+100)
		ans=s
		break
print(ans)