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):
  tmp = str(i).zfill(3)
  cnt =0
  for _ in range(len(c)):
    if tmp[s[_]-1]==str(c[_]):
      cnt +=1
  if cnt == len(c):
    print(i)
    exit()
print("-1")