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

combi_ary = []
for _ in range(M):
  s, c = map(int, input().split())
  combi_ary.append([s, c])

base = [-1, -1, -1]

exists = True
for combi in combi_ary:
  base_i = combi[0] - 1
  if(base[base_i] != -1 and base[base_i] != combi[1]):
    exists = False
    break
  else:
    base[base_i] = combi[1]

if (N == 3):
  if (base[0] == -1):
    base[0] == 1
  elif (base[0] == 0):
    exists = False
  else:
    if(base[1] == -1):
      base[1] = 0
    if(base[2] == -1):
      base[2] = 0
elif (N == 2):
  if (base[0] != -1):
    exists = False
  else:
    if(base[1] == -1):
      base[1] = 1
    elif(base[1] == 0):
      exists = False
    else:
      if(base[2] == -1):
        base[2] = 0
elif (N == 1):
  if (base[0] != -1):
    exists = False
  else:
    if(base[1] != -1):
      exists = False
    else:
      if (base[2] == -1):
        base[2] = 0

if(exists == False):
  print("-1")
else:
  result = ""
  for b in base:
    if (b == -1):
      continue
    else:
      result += str(b)
  print(result)