n,m = map(int,input().split())
if m > n:
	print(-1) ; exit()
lst = []
for i in range(m):
	lst.append(list(map(int,input().split())))

x = ['x','x','x']

for i in lst:
	if x[i[0]] == 'x':
		x[i[0]] = str(i[1])
	elif i[0] == 1 and i[1] == 0:
		print(-1) ; exit()
	else:
		print(-1) ; exit()
		
for i in range(len(x)):
	if x[i] == 'x':
		x[i] = '0'
	
print(int(''.join(x)))