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

if m == 0:
  print(10**n)
  exit()

st = 1
if n == 1:
  st = 0

ok = False
ans = -1
for i in range(st,10 ** n):
  ans = -1
  for j in range(m):
    ok = False
    if len(str(i)) >= sc[j][0]:
      if str(i)[sc[j][0]-1] == str(sc[j][1]) :
        ans = i
        if j == m-1 :
          ok = True
      else :
        break
    else:
      break
  if ok:
    break
      
print(ans)
      
