N, M = map(int, input().split())
sc = []

def check(num, sc):
  ret = True
  snum = format(num,'03d')
  for tmp in sc:
    s = tmp[0]
    c = tmp[1]
    
    if snum[s-1] != str(c):
      ret = False
  if snum[0] == "0":
    ret = False
  return(ret)

for i in range(M):
  sc.append(list(map(int,input().split())))
  
ret = -1
for num in range(1000):
  if check(num, sc):
    ret = num
    break

print(ret)
