N,M = map(int,input().split())
SC = [list(map(int,input().split())) for _ in range(M)]
flag = 1
for i in range(1000):
  if len(str(i)) < N:
    continue
  flag = 1
  for s,c in SC:
    c = str(c)
    if str(i)[s-1] != c:
      flag = 0
  if flag == 1:
    print(i)
    exit()

print(-1)