import sys

n, m = map(int, input().split())

num = [[0] for i in range(n)]
s = []

test = list(list(map(int, input().split())) for i in range(m))

for i in test:
  num[i[0] - 1].append(i[1])

for i in range(len(num)):
  if(len(set(num[i])) >= 3):
    print(-1)
    sys.exit()
  elif(i == 0 and max(num[i]) == 0 and n != 1):
    print(-1)
    sys.exit()
  elif(i == 0 and n != 1):
    num[0][0] = 1
  s.append(str(max(num[i])))

print(''.join(s))
