import sys

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(t[x[i][0]-1] > 0 and t[x[i][0]-1] != x[i][1]):
      print(-1)
      sys.exit()

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

if (n > 1 and t[0] == 0):
   print(-1)
   sys.exit()


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