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

t = [0] * n
for i in range(m):
   if(n > 1 and x[i][1] == 0):
      print(-1)
      exit()
   if(n > 1 and t[x[i][0]-1] > 0 and t[x[i][0]-1] != x[i][1]):
      print(-1)
      exit()

   t[x[i][0]-1] = x[i][1]

[print(t[i], end='') for i in range(m)]
print()
