N, M = map(int, input().split())
s = [input().split() for i in range(M)]
fl = 1

ans = -1
for num in range(1000):
  if fl == 0:
    break
  else:
    if len(str(num)) != N:
      continue
    for i in range(M):
        if int(str(num)[int(s[i][0])-1]) != int(s[i][1]):
          break
        elif i == M-1:
          ans = num
          fl = 0
print(ans)


		