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

A = [-1]*N

B = -1

for i in range(M):
  s,c = map(int,input().split())
  if A[s-1] == -1:
    A[s-1] = c
  else:
    if A[s-1] != c:
      B = 0
if B == 0 or (N != 1 and A[0] == 0):
  print(-1)
else:
  for i in range(len(A)):
    if A[i] == -1:
      A[i] = 0
  print(int("".join(map(str, A))))