import strutils, sequtils
var N, M: int
(N, M) = stdin.readLine.split.map(parseInt)
var ds = newSeqWith(N, -1)
proc f() =
  for d in ds: stdout.write if d == -1: 0 else: d
  echo()
var b = false
for _ in 1 .. M:
  var s, c: int
  (s, c) = stdin.readLine.split.map(parseInt); dec s
  if N > 1 and s == 0 and c == 0 or ds[s] >= 0 and ds[s] != c: echo -1; quit()
  ds[s] = c
  if c != 0: b = true
if b: f()
else:
  if N == 1: echo 0
  else: ds[0] = 1; f()