
n, m = map(int, input().split())
ary = [10 for i in range(n)]
a = []
for i in range(m):
	s, c = map(int, input().split())
	ary[s-1] = min(ary[s-1],c)
#print (ary)
for i in ary:
	if i == 10:
		print (-1)
		exit()
	else:
		break
ans = ""
if ary[0] == 0:
	print (-1)
	exit()
for i in range(len(ary)):
	if ary[i] == 10:
		ary[i] = 0
	ans += str(ary[i])
print (ans)