function Main(input) {
	input = input.split("\n");

	var l1 = input[0].split(" ");
	var N = l1[0];
	var M = l1[1];

	var values = [];
	var arrS = [];
	var arrC = [];
	var flag = true;

	for(var i = 0; flag && i < M; i++) {
		var l = input[1+i].split(" ");
		var s = parseInt(l[0]);
		var c = parseInt(l[1]);

		for(var j = 0; flag && j < arrS.length; j++) {
			if(arrS[j] == s) {
				if(arrC[j] != c) {
					flag = false;
				}
			}
		}
		arrS.push(s);
		arrC.push(c);

		var weight = Math.pow(10, N - s);
		values.push(weight * c);
	}

	values = values.filter(function(x, i, self) {
		return self.indexOf(x) === i;
	});
	var sum = 0;
	for(var i = 0; i < values.length; i++) {
		sum += values[i];
	}

	if(flag && sum > 0) {
		console.log(sum);
	} else {
		console.log(-1);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));