list1 = input().split(" ")
n = int(list1[0])
m = int(list1[1])
ansnum=[11]
for i in range(n-1):
	ansnum.append(11)

for i in range(m):
	list = input().split(" ")
	s = int(list[0])
	c = int(list[1])
	if c == 0 and s == 1 and n != 1:
		continue
	if s <= n:
		if int(ansnum[s-1]) > c:
			ansnum[s-1] = c

if len(ansnum) == 1 and ansnum[0] == 0:
	ans = 0
elif ansnum[0] == 11:
	ans = -1
else:
	ansnum = [0 if i == 11 else i for i in ansnum]
	ans = ''.join(map(str,ansnum))
	
print(ans)