"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();
  input = input.map(i => i.split(" ").map(Number));
  let result = new Array(digit).fill(0);

  let i = 0;
  for (; i < M; i++) {
    if (result[input[i][0] - 1] !== 0) break;
    result[input[i][0] - 1] = input[i][1];
  }

  if (result[0] !== 0) console.log(Number(result.join("")));
  else if (digit === 1) console.log(Number(result.join("")));
  else console.log(-1);
}
