N, M = map(int, input().split())
ans = [float('inf')] * N
for i in range(M):
	s, c = map(int, input().split())
	tmp = ans[s-1]
	if tmp > c:
		ans[s-1]=c
if ans[0] == float('inf') or ans[0] == 0 or len(ans) != N:
	print(-1)
else:
	for a in ans:
		print((a if not a == float('inf') else 0), end='')
print()
