const main = (input) => {
  const lines = input.trim().split("\n");
  const [N, M] = lines[0].split(' ').map(str => parseInt(str));
  const checkList = lines.slice(1).map(line => {
    const [s, c] = line.split(' ');
    return [parseInt(s - 1), c];
  });

  // 全探索
  // for (let i = 0; i < Math.pow(10, N); i++) {
  //   const strNum = i.toString();
  //   if (strNum.length == N && checkList.every(sc => strNum[sc[0]] === sc[1])) {
  //     console.log(strNum)
  //     process.exit(0);
  //   }
  // }
  // console.log(-1);

  // 順番に埋める
  const numList = Array(N).fill(0);
  checkList.forEach(sc => {
    sc[1] = parseInt(sc[1]);
    if (numList[sc[0]] !== 0 && numList[sc[0]] !== sc[1]) {
      console.log(-1);
      process.exit(0);
    }
    numList[sc[0]] = sc[1]
  })

  if (N >= 2 && numList[0] === 0) {
    console.log(-1);
    process.exit(0);
  }

  console.log(numList.join(""));


}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
