n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
tmp = [-1]*n
for j in range(m):
         if tmp[(sc[j][0]-1)] != sc[j][1]:
                  if tmp[(sc[j][0]-1)] != -1:
                           print(-1)
                           exit()
         tmp[(sc[j][0]-1)] = sc[j][1]
if tmp[0] == -1 and len(tmp) >= 2:
         print(-1)
         exit()
else:
         for k in range(n):
                  if tmp[k] == -1:
                           tmp[k] = 0
                  print("{}".format(tmp[k]), end = "")
