import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N, M = map(int, inp().split())
SC = [tuple(map(int, inp().split())) for _ in range(M)]
SC = sorted(SC, key=lambda x:(x[0],-(x[1])))
max_N = (SC[0][1]+1)*(10**(N-1))
min_N = 10**(N-1)

ans = 1005
for i in range(max_N, min_N, -1):
  x = str(i)
  cnt = 0
  for s, c in SC:
    if int(x[s-1]) == c:
      cnt += 1
  if cnt == M:
    ans = min(ans, i)
print(ans if ans < 1005 else -1)    
    
  

