
def myAnswer(N:int,M:int,S:list,C:list)-> int:
   dic = {key:[] for key in range(1,N+1)}
   for s,c in zip(S,C):
      dic[s].append(c)
   ans = 0
   for key,value in dic.items():
      if(value == []):
         value = [0]
      ans +=min(value) * 10**(N-key)
   return ans if(len(str(ans)) == N) else -1


def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   S= []
   C = []
   for _ in range(M):
      s,c =map(int,input().split())
      S.append(s)
      C.append(c)
   print(myAnswer(N,M,S[:],C[:]))

if __name__ == '__main__':
   main()