n, m = map(int, input().split())
rules = []

for x in range(m):
  rules.append(list(map(int, input().split())

def get_ans():
  if m == 0:
      return(10**(n-1)*int(bool(1<n)))

  for i in range(10**(n-1)*int(bool(1<n)), 10**n):
      for j, rule in enumerate(rules):

          if int(str(i)[rule[0]-1]) == rule[1]:
              if j == len(rules)-1:
                  return(i)
              else:
                  continue
          else:
              break
      return(-1)


print(get_ans())                    
