n,m = map(int,input().split())
s = []
c = []
while True:
  try:
    tmp = list(map(int,input().split()))
    s.append(tmp[0])
    c.append(tmp[1])
  except EOFError:
    break

for i in range(10**(n-1),1000):
  h = i // 100
  t = (i-100*h) // 10
  o = (i-100*h-10*t) // 1
  cnt = 0
  for _ in range(len(c)):
    if s[_]==1:
      if c[_]==h:
        cnt +=1
    elif s[_]==2:
      if c[_]==t:
        cnt +=1
    elif s[_]==3:
      if c[_]==o:
        cnt +=1
  if cnt==len(c):
    print(i)
    exit()
  elif i ==1000:
    print("-1")
    exit()