const main = (inputs) => {

  var array1 = inputs[0].split(" ");
  var N = Number(array1[0]);
  var M = Number(array1[1]);
  var scInput = [];
  var answer = -1;
  var setNumber = [];
  var getDigits = [];
  var flag = true;

  for (i = 1; i <= M; i++) {
    scInput = inputs[i].split(" ");
    var number = Math.floor(Number(Math.pow(10, N - scInput[0]) * scInput[1]));

    if (getDigits.indexOf(String(number).length) < 0) {
      if (number !== 0) {
        getDigits.push(String(number).length);
      }
      setNumber.push(number);
    } else {
      if (setNumber.indexOf(number) < 0)
        flag = false;
      else
        setNumber.push(number);
    }
  }

  if (flag) {
    var b = setNumber.filter(function (x, i, self) {
      return self.indexOf(x) === i;
    });

    var answer = b.reduce(function (prev, current, i, arr) {
      return prev + current;
    });
  }
  if (answer === 0) answer = -1;
  console.log(answer);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));