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

for i in range(m):
	list = input().split(" ")
	s = int(list[0])
	c = int(list[1])
	if s <= n:
		if int(ansnum[s-1]) > c:
			ansnum[s-1] = str(c)
		ans = ''.join(ansnum)

if len(ansnum) != 1 and ansnum[0] == '11':
	ans = -1
elif ansnum[0] == '0':
	ans = 0
	
print(ans)