def main():
  n,m = list(map(int,input().split()))
  number = [None for i in range(n)]
  #print(number)
  for i in range(m):
    tmp = list(map(int,input().split()))
    tmp[0] -= 1
    #print(tmp)
    #print(number[tmp[0]])
    if number[tmp[0]] == None:
      number[tmp[0]] = tmp[1]
    else:
      if number[tmp[0]] != tmp[1]:
        print(-1)
        return
  
  if number[0] == 0:
    print(-1)
    return
  
  if number[0] == None:
    number[0] = 1
  
  for i in range(1,n):
    if number[i] == None:
      number[i] = 0
  
  strnum = list(map(str,number))
  ans = ""
  for i in range(n):
    ans += strnum[i]
  
  print(int(ans))
  
main()