h = input()
k = h.split()
n = int(k[0])
m = int(k[1])

array = []
for i in range(m):
  array.append(0)

for i in range(m):
  z = input()
  t = z.split()
  a = int(t[0])
  b = int(t[1])
  r = a - 1
  array[r] = b;

while(array[0] == 0):
  array = array[1:]

result = ""
if(len(array) == n):
  for i in range(n):
    result = result + str(array[i])
else:
  result = "-1"


print(result)
  