class Condition:
  def __init__(self, s, c):
    self.pos = int(s) - 1
    self.char = c
    
  def is_match(self, number):
    return str(number)[self.pos] == self.char
  
N, M = map(int, input().split())
conditions = []
for _ in range(M):
  s, c = input().split()
  conditions.append(Condition(s, c))

for n in range(10 ** (N - 1), 10 ** N):
  if all(c.is_match(n) for c in conditions):
    print(n)
    break
else:
  print(-1)

