def main():
  n,m=map(int,input().split())
  dic={}
  for _ in range(m):
    s,m=map(int,input().split())
    if not (s in dic.keys()):
      dic[s]=m
    else:
      if dic[s]!=m:
        print(-1)
        return 0
  dic = sorted(dic.items(), key=lambda x:x[0],reverse=True)
  ans=0
  for s,m in dic:
    ans+=m*(10**(n-s))
  if len(str(ans))==n:
  	print(ans)
  else:
    print(-1)
main()