n,m = map(int,input().split())
ansnum = [99]
for i in range(n-1):
	ansnum.append(99)

for i in range(m):
	s,c = map(int,input().split())
	if ansnum[s-1] != 99 and ansnum[s-1] != c:
		n = 2
		ansnum[0] = 99
		break
	if n == 1 and c == 0:
		ansnum[s-1] = c
	elif n != 1 and s != 1:
		if ansnum[s-1] > c:
			ansnum[s-1] = c
	elif n != 1 and s == 1 and c != 0:
		if ansnum[s-1] > c:
			ansnum[s-1] = int(c)

if ansnum[0] == 99 and n == 1:
	answer = 0
elif ansnum[0] == 99 and n != 1:
	answer = -1
else:
	ansnum = [0 if i == 99 else i for i in ansnum]
	answer = ''.join(map(str,ansnum))
print(answer)