# -*- coding: utf-8 -*-

N, M = map(int, input().split())

error = False
ans = [-1 for n in range(N)]

for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1] == -1:
    ans[s-1] = c
  elif ans[s-1] != c:
    error = True
    break

# 先頭桁が0の場合はエラー
if ans[0] == 0:
  error = True

if error:
  print(-1)
  exit()

# -1の桁を0に置き換える（先頭桁は1にする）
ans = list(map(lambda n: 0 if n == -1 else n, ans))
if ans[0] == 0:
  ans[0] = 1

# 答えを計算
result = 0
for idx, elm in enumerate(ans):
  result += 10**(N-idx-1) * elm
print(result)