n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = ['0']*n
for s, c in sc:
  s -= 1 
  if ans[s] == '0' or ans[s] == str(c):
    ans[s] = str(c)
  else:
    print('-1')
    exit()

if ans == ['0']:
  print(0)
  exit()
if ans[0] == '0':
  print('-1')
  exit()

print(''.join(ans))