N, M = map(int, input().split())
result = {}
for i in range(1, N+1):
  result[i] = 10
for i in range(M):
  s, c = map(int, input().split())
  if result[s] > c:
    result[s] = c
if result[1] == 10 or result[1] == 0:
  print('-1')
else:
  for i in result.values():
    if i == 10:
      print('0', end='')
    else:
      print(i, end='')