const main = (input: string) => {
  const lines = input.trim().split("\n")
  const [N, M] = lines[0].split(" ").map(str => parseInt(str))
  const SC = lines.slice(1)
  const SCList: number[][] | number = []
  let combinedList = Array(N).fill(0)
  let combinedNumber;

  SC.forEach(sc => {
    SCList.push(sc.split(" ").map(str => parseInt(str)));
  })
  SCList.forEach(sc => {
    if(combinedList[sc[0] - 1] > sc[1]) {
      combinedList[sc[0] - 1] = sc[1]
    }
  })
  combinedNumber = combinedList.join("")

  let answer;
  answer = combinedNumber;
  if(combinedNumber.slice(0, 1) === "0") {
    answer = "-1";
  }
  console.log(answer)
}

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