n, m = list(map(int,input().split()))
# print(n,m)
l = {}
ok = True
conflict = False
for i in range(m):
  x, y = list(map(int,input().split()))
  if (x in l):
    if l[x] != y:
      ok = False
      conflict = True
      break
  else:
    l[x] = y
ret = ""
isFirstZero = False
for i in range(n):
  keta = i + 1    
  if keta in l:
    if keta == 1:
      if l[keta] == 0:
        ok = False
        isFirstZero = True
        l.pop(keta)
        break
      else:
        ret = ret + str(l.pop(keta))
    else:
      ret = ret + str(l.pop(keta))
  else:
    ret = ret + "0"
if len(l) > 0:
  ok = False
if isFirstZero:
  if len(l) == 0:
    ok = True
    ret = 0
if conflict:
  print(-1)
else:
  if ok:
    print(int(ret))
  else:
    print(-1)
