import sys
n, m = map(int, sys.stdin.readline().split())
li = [{}] * n
res = 0
for _ in range(m):
  a, b = map(int, sys.stdin.readline().split())
  li[a-1].add(b)
for i in li:
  if len(i) >= 2:
    res = -1
    break
  else:
    res += i * 10**(n-1)
    n -= 1
  