N, M = map(int, input().split())
q = [list(map(int, input().split())) for i in range(M)]
change = [0 for i in range(N)]

ans = -1
for i in range(10 ** 3):
  flag = True
  for j in range(M):
    if str(i)[q[i][0] - 1] != q[i][1]:
      flag = False
      
  if flag:
    ans = i
    break
    
print(ans)