N, M = map(int, input().split())
ans = -1
cond = []
for i in range(M):
  cond.append(list(map(int, input().split())))
for i in range(10**3):
  D = True
  s = str(i)
  for j in range(M):
    if N > len(s):
      D = False
      break
    if s[cond[j][0]-1] != str(cond[j][1]):
      D = False
      break
  if D == True:
    ans = i
    break
print(ans)