n, m = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for _ in range(m)]


def ng():
  print('-1')
  exit()


d = {}
for s, c in sc:
  if s in d and d[s] != c:
    ng()
  d[s] = c

ans = [''] * (n + 1)
for s, c in sc:
  ans[s] = str(c)

for i in range(1, n + 1):
  if ans[i] == '':
    ans[i] = '0'

if ans[1] == '0':
  ng()

print(int(''.join(ans[1:])))
