import sys
input = sys.stdin.readline
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for _ in range(M)]
for x in range(1, 10 ** N):
  f = 1
  for i in range(M):
    s = str(x)
    y, c = t[i]
    if len(s) < y or (len(s) < N):
      f = 0
      break
    if int(s[y - 1]) != c:
      f = 0
      break
  if f:
    print(x)
    exit(0)
print(-1)