kensa = 0
kekka = ""
num = []
hantei = "OK"
INF = input().split()
gyosu = int(INF[1])
keta = int(INF[0])
out = []
for l in range(keta):
  out.append(0)


for i in range(gyosu):
  num.append([int(j) for j in input().split()])

if gyosu >0:
  for j in range(gyosu-1):
    for k in range(gyosu-1):
      if num[j][0] == num[k + 1][0]:
        if num[j][1] != num[k + 1][1]:
          hantei = "NG"
          
    if num[j][0] == keta:
      if num[j][1] == 0:
        hantei ="NG"

if hantei == "NG":
  print("-1")
else:
  for m in range(gyosu):
    out[(num[m][0] - 1)] = num[m][1]
    #print(out)
  for n in range(keta):
    kekka = kekka + str(out[n])

  for p  in kekka:
      if p == "0":
        kensa = kensa + 1
      else:
        break
  for q in kensa:
    kekka.rstrip("0")

#    if n == 0 and keta != 1 and gyosu != 0:
      #print("-1")
      #hantei = "NG"

if hantei == "OK":
  if gyosu == 0:
    print(0)
  else:
    print(kekka)