if __name__ == '__main__':
	N, M = map(int, input().split())
	flg = 0
	lst = [-1,-1,-1]
	for i in range(M):
		s, c = map(int, input().split())
		if lst[s-1] != -1:
			if lst[s-1] != c:
				flg = 1
				break
		else:
			lst[s-1] = c

	a = 0

	if lst[0] == 0:
		flg = 1

	for i in range(N):
		if lst[i] != -1:
			a += lst[i] * 10**(N-i-1)

	if len(str(a)) < N:
		a += 10**N

	if flg == 1:
		print(-1)
	else:
		print(a)
