n, m = map(int, input().split())
l = [''] * n
ans = 0
for i in range(m):
  s, c = map(int, input().split())
  if ans == 0:
    if s == 1 and c == 0 and n >= 2:
      ans = -1
    else:
      if l[s - 1] == '':
        l[s - 1] = c
      elif l[s - 1] != '' and l[s - 1] == c:
        next
      elif l[s - 1] != '' and l[s - 1] != c:
        ans = -1
if ans == 0:
  ans = ''
  for e in l:
    if e == '':
      e = 0
    ans += str(e)
print(ans)