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

num = [1] + [0]*(N-1)

dic = {}

for i in range(M):
	s, c = list(map(int, input().split()))
	
	if(s == 1 and c == 0):
		print(-1)
		exit(0)

	if(s in dic):
		if(dic[s] != c):
			print(-1)
			exit(0)

	dic[s] = c
	num[s-1] = c

n = 0
for i in range(N):
	n += num[i] * 10 ** (N-i-1)

print(n)