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

for i in range(0, 1000):
  flg = True
  for j in l:
    si = str(i)
    if len(si) < j[0]:
      flg = False
      continue

    if si[j[0]-1] != str(j[1]):
      flg = False
      
  if flg == True:
    print(i)
    break
else:
  print(-1)
