"use strict";
main(
  require("fs")
    .readFileSync("/dev/stdin", "UTF-8")
    .trim()
    .split("\n")
);

function main(input) {
  const digit = Number(input[0].split(" ")[0]);
  let M = Number(input[0].split(" ")[1]);
  input.shift();
  let result = new Array(digit).fill(0);
  let message = null;

  for (let i = 0; i < M; i++) {
    let condi = input.shift().split(" ");
    let left = Number(condi[0] - 1);
    let num = Number(condi[1]);

    if (result[left] > 0 && result[left] !== num) message = -1;
    result[left] = num;
  }

  if (result.length > 1 && result[0] === 0) message = -1;

  if (message) console.log(message);
  else console.log(Number(result.join("")));
}
