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

num = [10, 10, 10]
for i in range(M):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    print(-1)
    exit()
  elif num[s - 1] == 10 or num[s - 1] == c:
    num[s-1] = c
  else:
    print(-1)
    exit()

if num[0] == 10:
  num[0] = 1
if num[1] == 10:
  num[1] = 0
if num[2] == 10:
  num[2] = 0

for place in range(3):
  print(num[place], end = "")