if __name__ == '__main__':

	n,m = map(int,input().split())
	
	A = [0 for _ in range(n)]

	for i in range(m):
		s,c = map(int,input().split())
		if A[s-1] != 0:
			A[s-1] = min(A[s-1],c)
		else:
			A[s-1] = c
	
	ans = ""
	if A[0] == 0 and n != 1:
		ans = -1
	else:
		for j in range(n):
			ans += str(A[j])
	print(ans)

