n, m = [int(elem) for elem in input().split()]

dic = {}
flag = 0
for i in range(m):
  s, c = [int(elem) for elem in input().split()]
  if not s in dic:
    dic[s] = c
  else:
    if dic[s] == c:
      pass
    else:
      flag = -1
      break
    
if flag == -1:
  print(flag)
else:
  res = ""
  for i in range(1, n+1):
    if i in dic:
      res += str(dic[i])
    else:
      res += "0"
  if res[0] == "0":
    print(-1)
  else:
    print(res)