import sys

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

tmp = [0] * n
for s, c in sc:
  if tmp[s-1]!=c and tmp[s-1] > 0:
    print(-1)
    sys.exit(1)
  else:
    tmp[s-1] = c

result = ''.join(map(str, tmp))
int_result = int(result)

print(result, int_result, str(int_result))
print(result if result==str(int_result) else -1)