def check(m, x):
  for i in range(m):
    s, c = map(int, input().split())
   
    if x.get(s) == None or x.get(s) == c:
      x[s] = c
    else:
      return -1
  
  if x[1] == 0:
    x.pop(1)
  return "".join([str(v) if v else str(0) for v in x.values()])


n, m = map(int, input().split())
x = {i: None for i in range(1, n+1)}

print(check(m, x))