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

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

if ansnum[0] == '0':
	ans = -1
print(ans)