N, M = [int(a) for a in input().split()]
S = [[int(i) for i in input().split()] for _ in range(M)]
if([1,0] in S):
  print(-1)
else:
  NUM = 0
  LIST = [-1 for _ in range(M)]
  for s,c in S:
    s -= 1
    if(LIST[s]==-1):
      NUM += c*(10**(N-s-1))
      LIST[s] = c
    else:
      if(LIST[s]!=c):
        print(-1)
        break
      else:
        continue
  if(LIST[0] == -1):
    NUM += 10**(N-1)
  print(NUM)