NM = input().split()
N = int(NM[0])
M = int(NM[1])

solution = 0
S = []
C = []

for i in range(M):
	if solution == 1:
		break
 
	sc = input().split()
	s = int(sc[0])
	c = int(sc[1])
    
	if c == 0:
		if s != N:
			solution = -1
  
	if(s in S):
		if c == C[S.index(s)]:
			break
		else:
			solution = -1
	else:
		S.append(s)
		C.append(c)
		solution += c * (10**(N-s))
      
 
print(solution)

  