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