def abc157_c():
  n, m = map(int, input().split())
  query = [tuple(map(int, input().split())) for _ in range(m)]
  # 推定される桁ごと、-1は未定
  pred = [-1] * n
  for s, c in query:
    # まだ決まっていなければ、当てはめる
    if pred[s-1] == -1:
      pred[s-1] = c
    # 決定済みの桁で、競合したらNG
    elif pred[s-1] != c:
      return -1

  # 先頭が0は不正
  if pred[0] == 0:
    return -1
  # 最小値で埋める(先頭桁なので0はダメで1)
  if pred[0] == -1:
    pred[0] = 1
  # 最小値で埋める
  if n >= 2 and pred[1] == -1:
    pred[1] = 0
  if n >= 3 and pred[2] == -1:
    pred[2] = 0
  # 数字に復元
  ans = 0
  for i in range(n):
    ans += (10**i) * pred[-(i+1)]
  return ans

ans = abc157_c()
print(ans)