// inputに入力データ全体が入る
function Main(input) {
    var N = input[0].split(" ")[0]-0;
    var M = input[0].split(" ")[1]-0;
    var list = input.filter((v,i)=>i>0).map(v=>v.split(" ").map(v=>v-0));
    var ans = -1;
    start:for(var i=0;i<=999;i++){
        var str = i.toString();
        if(str.length != N) continue;
        for(var j=0;j<M;j++){
            var s = list[j][0];
            var c = list[j][1];
            if(str[s-1] != c) continue start;
        }
        ans = i;
        break;
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));