N, M = [int(a) for a in input().split()]
S = [[int(i) for i in input().split()] for _ in range(M)]
flag = 0
NUM = 0
LIST = [-1 for _ in range(N)]
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):
        flag = 1
        print(-1)
        break
        else:
          continue
          if(LIST[0] == -1):
            if(N>1):
              NUM += 10**(N-1)
              else:
                NUM = 0
                elif(LIST[0] == 0):
                  if(N>1):
                    print(-1)
                    flag = 1
                    else:
                      NUM = 0
                      if(flag==0):
                        print(NUM)