def main():
  import sys
  input = sys.stdin.readline
  n,m=map(int,input().split())
  sc=[list(map(int,input().split())) for _ in range(m)]
  sc=sorted(sc,key=lambda x: (x[0],x[1]))
  l=[0.0]*n
  if n==1:
    if sc[0][1]==sc[-1][1]:
      print(sc[0][1])
      exit()
    else:
      print(-1)
      exit()
  for i in range(len(sc)):
    if type(l[sc[i][0]-1])==float:
      l[sc[i][0]-1]=sc[i][1]
    else:
      if l[sc[i][0]-1]!=sc[i][1]:
        print(-1)
        exit()
  if len(''.join([str(int(i)) for i in l]))==n and int(''.join([str(int(i)) for i in l]))>=pow(10,n-1):
    print(int(''.join([str(int(i)) for i in l])))
  else:
    print(-1)
  
if __name__ == '__main__':
    main()