n, m = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(set)
for i in range(m):
  s, c = list(map(int, input().split()))
  d[s].add(c)

s = ""
for i in range(1, n+1):
  if i == 1 and d[i] == set():
    s += "1"
  elif i == 1 and list(d[i])[0] == 0:
    print(-1)
    exit()
  elif d[i] == set():
    s += "0"
  elif len(d[i]) >= 2:
    print(-1)
    exit()
  else:
    s += str(list(d[i])[0])

print(s)