n, m = map(int, input().split())
sc = []
s=[]
c=[]
for i in range(m):
	_s, _c = map(int, input().split())
	s.append(_s-1)
	c.append(_c)

if m==0:
	if n==1:
		print(0)
		exit()
	else:
		print(-1)
		exit()
ans = -1
for i in range(1000):
	*t, = map(int, list(str(i)))

	if len(t) != n:
		continue

	ok = True
	for j in range(m):
		if t[s[j]]!=c[j]:
			ok = False
			break
 
	if ok:
		print(i)
		quit()

print(-1)