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

d = [-1] * N
res = 0

for _ in range(M):
  s,c = list(map(int, input().split()))

  if(d[s-1] == -1 or d[s-1] == c):
    d[s-1] = c
  else:
    res = -1


if(res == -1):
  print(res)
elif (d[0] == 0):
  res = -1
  print(res)
else:
  res = ""
  for value in d:
    if(value == -1):
      res += "0"
    else:
      res += str(value)

print(res)
  
