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 = ["0"]*n
if c_list[0] == 0:
  ans = ["-1"]
else:
  for i, s in enumerate(s_list):
    x = c_list[i]
    if ans[s-1] != "0" and ans[s-1] != str(x):
      ans = ["-1"]
      break
    ans[s-1] = str(x)
print(int("".join(ans)))