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

ret = int(ret)
if ok:
  if (ret < 10**(n-1)) and n > 1:
    print(ret + 10**(n-1))
  else:
    print(ret)
else:
  print(-1)
