N, M = map(int, input().split())
SC = [list(map(int, input().split()))for i in range(M)]
ans=-1
a=[0,0,0]
for i in range(1,1000):
	if i//10**(N-1)==0:continue
	a[0] = i//100
	a[1] = i%100//10
	a[2] = i%100%10
	for j in range(M):
		if a[SC[j][0]-1] != SC[j][1]:break
	else:
		ans=i
		break
print(ans)
