
function Main(arg)
{
  var N = arg.split("\n")[0].split(" ")[0]-0;
  var M = arg.split("\n")[0].split(" ")[1]-0;
  var c = arg.split("\n").slice(1);

  var arr = new Array(N);
  arr.fill(0);
  for (var i = 0; i < M; i++){
    var idx = (c[i].split(" ")[0] - 0)-1;
    var tmp = c[i].split(" ")[1] - 0;
    if (arr[idx] === 0) {
      arr[idx] = tmp;
      continue;
    }

    if (arr[idx] === tmp) {
      continue;
    }
    console.log(-1);
    return;
  }

  var ans = arr.join("")-0;

  console.log(ans === 0 ? -1 : ans);
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));