N,M = list(map(int,input().split()))

x = ["a"]*N

data = [[0,0] for _ in range(M)]
for m in range(M):
	data[m] = list(map(int,input().split()))

for m in range(M):
	s,c = data[m]
	s = int(s)
	if x[s-1] == "a":
		x[s-1] = str(c)
	elif int(x[s-1]) != c:
		print("-1")
		exit()

if N == 2:
	if x[0] == "a":
		x[0] = "1"
	if x[1] == "a":
		x[1] = "0"
	if x[0] == "0":
		print("-1")
		exit()

if N == 3:
	if x[0] == "a":
		x[0] = "1"
		if x[1] == "a":
			x[1] = "0"
		if x[2] == "a":
			x[2] = "0"
	elif x[0] == "0":
		print("-1")
		exit()
	else:
		if x[1] == "a":
			x[1] = "0"
		if x[2] == "a":
			x[2] = "0"

for i in range(N):
	print(x[i],end = "")

