#C - Guess The Number
n,m = list(map(int,input().split()))
tmp = []
s = []
c = []
flg = False
counter = 0
ans = 0
tmp = [input() for i in range(m)]
for i in tmp:
    i.split()
    s.append(i[0])
    c.append(i[2])
if(n ==3):
  for j in range(100,1000):
    if(flg == True):
      break
    list_j = list(str(j))
    counter = 0
    for k in s:
        if(list_j[int(k)-1] != c[counter]):
          break
        if(list_j[int(k)-1] == c[counter]):
          counter += 1
          if(counter == len(c)):
            flg = True
            break
    if(flg == True):
      ans = j
      break
if(n ==2):
  for j in range(10,100):
    if(flg == True):
      break
    list_j = list(str(j))
    counter = 0
    for k in s:
        if(list_j[int(k)-1] != c[counter]):
          break
        if(list_j[int(k)-1] == c[counter]):
          counter += 1
          if(counter == len(c)):
            flg = True
            print(flg)
            break
    if(flg == True):
      ans = j
      break
if(n ==1):
  for j in range(0,10):
    if(flg == True):
      break
    list_j = list(str(j))
    counter = 0
    for k in s:
        if(list_j[int(k)-1] != c[counter]):
          break
        if(list_j[int(k)-1] == c[counter]):
          counter += 1
          if(counter == len(c)):
            flg = True
            print(flg)
            break
    if(flg == True):
      ans = j
      break

if(flg == True):
    print(ans)
else:
    print('-1')
