import sys
n, m = map(int, input().split())
num = [-1]*n

if n == 1 and m == 0:
  print(0)
  sys.exit()

for _ in range(m):
  s, c = map(int, input().split())

  # 一桁目が0
  if s == 1 and c == 0:
    print(-1)
    sys.exit()
  # 同じ桁が指定される
  if num[s-1] != -1 and num[s-1] != c:
    print(-1)
    sys.exit()
  num[s-1] = c

if num[0] == -1:
  num[0] = 1
for i in range(1, n):
  if num[i] == -1:
    num[i] = 0

for i in num:
  print(i, end='')