function Main(input){
	input = input.split("\n");
	temp = input[0].split(" ");
	var N = parseInt(temp[0],10);
	var M = parseInt(temp[1],10);
	var nums = [];
	for(var i = 0;i<N;i++)nums[i]=10;
	for(var i = 0 ;i < M;i++){
		temp = input[i+1].split(" ");
		var s = parseInt(temp[0],10);
		var c = parseInt(temp[1],10);
		if(nums[s-1] > c)nums[s-1] = c;
	}
	if(nums[0] === 10 || nums[0] === 0 && nums.length > 1){
		console.log(-1);
	}else{
		var result = 0;
		for(var i =0;i<N;i++){
			if(nums[i]==10)nums[i] = 0;
			n = dd(nums[i],N-i-1,10);
			result+=n;
		}
		console.log(result)
	}
}
function dd(num,digit,base){
	for(var i=0;i<digit;i++)num = num*base;
	return num;
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));
