import sys
n, m = list(map(int, input().split()))
res = [list(map(int, input().split())) for _ in range(m)]

ans = [-1 for _ in range(n)]

for r in res:
	if ans[r[0] - 1] >= 0:
		if ans[r[0] - 1] != r[1]:
			print(-1)
			sys.exit()
	ans[r[0] - 1] = r[1]

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

#print(res, ans)
ans = [a if a >= 0 else 0 for a in ans]

print("".join([str(a) for a in ans]))