n, m = map(int, input().split())
li = []
a = 0
for i in range(m):
  li.append(list(map(int, input().split())))
li_n = [0 for i in range(n)]
for i in range(m):
  if li[i][0] > n:
    a += 1
  else:
    for i in range(m):
      if li_n[li[i][0]-1] == 0:
        li_n[li[i][0]-1] = li[i][1]
      elif li_n[li[i][0]-1] != 0:
        if li_n[li[i][0]-1] == li[i][1]:
          continue
        else:
          a += 1
for i in range(m):
  if n == 1:
    a = 0
  elif li[i][0] == 1:
    if li[i][1] == 0:
      a += 1
if li_n[0] == 0 and n != 1:
  li_n[0] += 1
if n == 1:
  b = 0
  c = 0
  for i in range(m):
    if li[i][1] == 0:
      b += 1
    elif li[i][1] != 0:
      c += 1
  if b*c != 0:
    a += 1
if a != 0:
  print(-1)
else:
  for i in range(n):
    li_n[i] = str(li_n[i])
  li_n = "".join(li_n)
  print(li_n)