import sys
import math

N, M = map(int, input().split())

s, c = [0] * N, [0] * N
for i in range(M):
	s[i], c[i] = map(int, input().split())

for i in range(0 if N == 1 else 10 ** (N - 1), 10 ** N):
	x = str(i)
	for j in range(M):
		if x[s[j] - 1] != str(c[j]):
			break
		elif j == M - 1:
			print(i)
			sys.exit(0)

print(-1)