N, M = [int(x) for x in input().split(' ')]
r = [0, -1, -1, -1]
for _ in range(M):
  s, c = [int(x) for x in input().split(' ')]
  s += 3 - N
  if r[s] != -1 and r[s] != c:
    print(-1)
    break  # -1
  r[s] = c
else:
  if N == 1:
    if r[1] == r[2] == -1 and r[3] >= 0:
      print(r[3])
    else:
      print(-1)
  elif N == 2:
    if r[1] == -1 and r[2] > 0:
      print('{}{}'.format(r[2],
                          0 if r[3] == -1 else r[3]))
    else:
      print(-1)
  elif N == 3:
    if r[1] > 0:
      print('{}{}{}'.format(r[1],
                            0 if r[2] == -1 else r[2],
                            0 if r[3] == -1 else r[3]))
    else:
      print(-1)