function Main(inputs) {
  var lines = inputs.split('\n');
  var N = lines[0].split(' ')[0];

  var flag = 0;
  var ns = Array.from({ length : N });

  lines.slice(1)
  .filter(v=>v != '')
  .forEach(line=>{
    var s = (+line.split(' ')[0]) - 1;
    var c = (+line.split(' ')[1]);

    if(ns[s] != null && ns[s] != c){
      flag = 1;
    }
    ns[s] = c
  })

  if(ns[0] == 0)    { flag = 1 }
  if(ns.length > N) { flag = 1 }

  var first = ns[0] || 1;
  var n = [ first, ...ns.slice(1).map(v=> v || 0) ].join('');

  console.log(flag  == 0 ? n : -1)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

