N, M = list(map(int, input().split()))

def check():
  if M == 0:
    res = ['0' for _ in range(N)]
    res[0] = '1'
    return int(''.join(res))
  s = []
  c = []
  m = {}
  for i in range(M):
    si, ci = list(map(int, input().split()))
    if si in m:
      if m[si] != ci:
        return -1
    else:
      m[si] = ci
    s.append(si)
    c.append(ci)
  if c[-1] == 0:
    return -1
  res = ['0' for _ in range(N)]
  for k, v in m.items():
    res[k-1] = str(v)
  #print(res)
  return int(''.join(res))
print(check())