"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    const sc = arg.slice(1, M + 1).map(n=>n.split(" "));
    
    let answer = new Array(N).fill("x");

    for(let i in sc) {
        let digit  = parseInt(sc[i][0]);
        let number = sc[i][1];
        
        // console.log("answer:" + answer);
        // console.log("a:" + answer[digit - 1]);
        // console.log(answer[digit - 1] !== "x");
        
        // すでに他の数字で確保されているのはNG
        if(answer[digit - 1] !== number && answer[digit - 1] !== "x") {
            console.log(-1);
            return;
        }

        answer[digit - 1] = number;
    }
    
    // 最小を考える
    for(let i in answer) {
        if(answer[i] === "x") {
            answer[i] = 0;
        }
    }
    
    console.log(parseInt(answer.join("")).length === N ? answer.join("") : -1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));