def f():
  n, m = list(map(int, input().split()))
  a = [-1, -1, -1, -1]

  for c in range(m):
    x = list(map(int, input().split()))
    if(a[x[0]] == -1):
      a[x[0]] = x[1]
    else:
      if(a[x[0]] != x[1]):
        return -1
  for y in range(4):
    if(a[y] == -1):
      a[y] = 1
  #print(a)
  
  s = 0
  for i in range(1,4):
    s *= 10
    s += a[i]
    
    #print(s)
  if(len(list(str(s))) != n):
    return -1
  return s

    




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

