def f():
  n, m = list(map(int, input().split()))

  x = []

  for i in range(m):
      x.append(list(map(int, input().split())))

  x = sorted(x, key=lambda y: y[0])
  #print(x)
  ns = [0, 0, 0, 0]
  aa = [0, 0, 0, 0]
  mynum = 0
  for c in x:
    #print(mynum)
    if(ns[c[0]] == 0):
      mynum = mynum*pow(10,c[0]-1)
      ns[c[0]] = 1
      aa[c[0]] = c[1] 
      mynum += c[1]
    else:
      if(aa[c[0]] != c[1]):
        return -1
  if(len(list(str(mynum))) != n):
    return -1
  return mynum

x = f()
if(x == -1):
  print("-1")
else:
  print(x)

