function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = input[0];
  var B = input[1];
  input = input.splice(2);
  var ans = [];
  var flg = true;
  var numche = 1;
  for(var i=0;i<A;i++){
    ans[i]="a";
    numche*=10;
  }
  numche/=10;
  for(var i=0;i<B*2;i+=2){
    var s = Number(input[i]) - 1;
    var c = input[i+1];
    if(ans[s]=="a" || ans[s]==c){
      ans[s]=c;
    }else{
      flg=false;
      break;
    }
  }

  var num = 0;
  for(var i=0;i<A;i++){
    if(ans[i]=="a"){
      num+="0";
    }else{
      num+=ans[i];
    }
  }
  num = Number(num);
  if(num%numche==0){
    flg=false;
  }


  if(flg){
    console.log(num);
  }else{
    console.log(-1);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));