n, m = map(int, input().split())
s = [0 for i in range(m)]
c = [0 for i in range(m)]
ans = 0
for i in range(m):
  tmp1, tmp2 = map(int, input().split())
  if tmp1 in s:
    if c[s.index(tmp1)] != tmp2:
      ans = -1
      break
  else:
    ans += 10 ** (n - tmp1) * tmp2
    s[i] = tmp1
    c[i] = tmp2
if len(str(ans)) != n:
  ans = -1
print(ans)