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

flag = False
for i in range(n):
  if ans[i] == '-1' and flag:
    ans[i] = '0'
  elif ans[i] == '-1' and flag == False:
    print('-1')
    exit()
  else:
    flag = True

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

if int(''.join(ans)) >= 10**(n-1):
  print(''.join(ans))
else:
  print('-1')