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
  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)
