N, M = map(int, input().split())
SC = {}
for _ in range(M):
  s, c = map(int, input().split())
  # 同じ桁に違う値 or Nより大きい桁数
  if (s in SC and SC[s] != c) or (s > N):
    print(-1)
    import sys; sys.exit()
  SC[s] = c

if 1 in SC:
  if N == 1 and SC[1] == 0:
    print(0)
    import sys; sys.exit()
  elif N > 1 and SC[1] == 0:
    print(-1)
    import sys; sys.exit()
else:
  SC[1] = 1

num = 0
for n in range(1, N+1):
  num *= 10
  if n in SC:
    num += SC[n]

print(num)