N, M = [int(i) for i in input().split()]
s_c = [[int(i) for i in input().split()] for _ in range(M)]
s_c = list(map(list, set(map(tuple, s_c))))

number = {}
for i in s_c:
  if i[0] in number:
    print(-1)
    exit()
  number[i[0]] = i[1]

ans = 0
for i in range(1, N+1):
  if N+1-i in number:
    ans+=number[N+1-i]*(10**(i-1))

if len(str(ans)) < N:
  print(-1)
  exit()

print(ans)
