n, m = map(int, input().split())
s = []
c = []
for i in range(m):
  _s, _c = map(int, input().split())
  s.append(_s)
  c.append(_c)

s = [0, 0, 10, 100]
g = [10, 10, 100, 1000]
for i in range(s[n], g[n]):
  i_str = str(i)
  for j in range(m):
    if i_str[s[j]-1] != str(c[j]):
      break
  else:
    print(i)
    break
else:
  print(-1)