n,m = map(int,input().split())
s = [0]*m
c = [0]*m
ans = 0
g = 0

if m == 0:
	g += 1

for i in range(m):
	s[i],c[i] = map(int,input().split())

for i in range(m):
	if s[i] == 1 and c[i] == 0:
		g += 1

	for j in range(m):
		if s[i] == s[j] and c[i] != c[j]:
			g += 1

c = sorted(set(c), key=c.index)
s = sorted(set(s), key=s.index)

for i in range(len(s)):
	ans += c[i]*pow(10,n-s[i])

if ans < pow(10,n-1):
	ans += pow(10,n-1)

if g > 0:
	print(-1)
else:
	print(ans)