NM = input().split()
N = int(NM[0])
M = int(NM[1])

sc = []
flg = False
for i in range(M):
  scc = input().split()
  sc.append([int(scc[0]), int(scc[1])])
  if int(scc[0]) == 1 and int(scc[1]) == 0:
    flg = True
else:
  string = ["0"]*N
  sc.sort(key=lambda x: x[0])
  s = []
  for i in range(M):
    if flg:
      break
    if i != M-1:
      if s and sc[i][0] == s[0][0]:
        s.append(sc[i])
      elif not s:
        s.append(sc[i])
      else:
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
        s = []
        s.append(sc[i])
    else:
      if sc[i][0] == s[0][0]:
        s.append(sc[i])
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
      else:
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
        string[int(sc[i][0])-1] = str(sc[i][1])


if flg:
  print(-1)
else:
  string = "".join(string)
  if string == "0"*N:
    print('-1')
  else:
    print("".join(string))