N, M = map(int, input().split())
A = [None]*N
B = 1000
for i in range(M):
  s,c = map(int, input().split())
  if A[s-1]==None:
    A[s-1] = c
  elif A[s-1] != c:
    B = -1
    break
if A[0]==0:
  B = -1
F = 0
for i in range(N):
  if A[-1-i] == None:
    A[-1-i] = 0
  F += A[-i-1]*10**i
print(min(B,F))