import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd

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

for i in range(10^n):
  X=str(i)
  tf=True
  if len(X)==n:
    for j in SCs:
      if X[SCs[0]]!=SCs[1]:
        tf=False
    if tf:
      print(i)
      sys.exit()
print(-1)