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

NUM = [0]*n
for s, c in SC:
    if NUM[n-s] == 0:
        NUM[n - s] = c
    elif NUM[n-s] != 0 and NUM[n-s] != c:
        print("-1")
        exit()

if NUM[n-1] == 0:
  print(-1)
  exit()

for s in NUM[::-1]:
  print(s, end ="")
  