N, M = map(int,input().split())
list1 = [tuple(map(int,input().split())) for _ in range(M)]
list2 = [None for _ in range(N)]
imp = False
for nums in list1:
  s, c= nums[0]-1, nums[1]
  if list2[s] == c or list2[s] == None:
    list2[s] = c
  else:
    imp = True
if list2[0] == None:
  list2[0] = 1
if (list2[0] == 0 and N != 1) or imp:
  print(-1)
else:
  for s in list2:
    if s == None:
      s = 0
    print("{}".format(s),end='')
  