import sys
n,m = map(int,input().split())

s = []
c = []

for i in range(m):
	S,C = map(int,input().split())
	s.append(S)
	c.append(C)

for i in range(m-1):
	for j in range(i+1,m):
		if s[i] == s[j]:
			if c[i] != c[j]:
				print("-1")
				sys.exit()


num = 10**(n)
num_g = list(str(10**(n-1)))

for i in range(len(s)):
	num_g[s[i]-1] = str(c[i])

ans = ""
for i in range(len(num_g)):
	ans += num_g[i]

if ans[0] == "0" and n > 1:
	print("-1")
	sys.exit()

if int(ans) >= num:
	print("-1")
else:
	print(ans)