import sys

# バリデーション
# ルール１：同じ桁数に複数の値を割り当てることはできない
# ルール２：一桁目に０は入れることができない
# ルール３：範囲外の値を入れることができない
def check_sets():
  # check_lists = {}
  # if [1, 0] in sets and N != 1:
  #   return True
  # for a,b in sets:
  #   if a not in check_lists:
  #     check_lists[a] = b
  #   else:
  #     if check_lists[a] != b:
  #       return True
  if N > 1 and any(cond == (1, 0) for cond in sets):  # 1st digit mustn't be 0 if N > 1
      return -1
  result = [-1] * N
  for digit, num in sets:
      if result[-digit] >= 0 and result[-digit] != num:
          return -1
      result[-digit] = num
  if result[-1] == -1:  # 1st digit must be 1 if N > 1 (no leading zeros)
      result[-1] = 1 if N > 1 else 0

  return False

N, M = list(map(lambda x: int(x), input().split()))
# 配列作るか
ans_strs = ['0' for _ in range(N)]
ans_strs[0] = '1'

sets = []
for _ in range(M):
  sets.append(list(map(lambda x: int(x), input().split())))

is_bad = check_sets()
if is_bad:
  print(-1)
  sys.exit()

for index,number in sets:
  ans_strs[index - 1] = str(number)

answer = int(''.join(ans_strs))
if answer == 1:
  answer = 0
print(answer)
