n, m = map(int, input().split())

s_list = []
c_list = []
for _ in range(m):
  s, c = map(int, input().split())
  s_list.append(s)
  c_list.append(c)

ans = ["x"]*n

if m <= 1:
    ans[s_list[0]-1] = str(c_list[0])
else:
  for s, c in zip(s_list, c_list):
    if len(ans) < s:
      ans = ["-1"]
      break
    elif ans[s-1] != "-1" and ans[s-1] != str(c):
      ans = ["-1"]
      break
    ans[s-1] = str(c)
  if ans[0] == "0":
    ans = ["-1"]
  else:
    ans = ["0" if a == "x" else a for a in ans]
print("".join(ans))