function Main(input){
  	var temp = input.split("\n");
  	var N = parseInt(temp[0].split(" ")[0]);
  	var M = parseInt(temp[0].split(" ")[1]);
  	var res = [10,10,10];
  	var snum = 1;
  	for(var i = 0;i<M;i++){
      var s = parseInt(temp[snum+i].split(" ")[0]);
      var c = parseInt(temp[snum+i].split(" ")[1]);
      if(res[s-1] > c)res[s-1] = c;
    }
  	res = res.map(num => num==10?0:num);
  	var strnum = String(res[0]) + String(res[1]) + String(res[2]);
  	if(String(parseInt(strnum)).length == N){
    	console.log(parseInt(strnum));
    }else{
    	console.log(-1);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));