'use strict'
const Main=input=>{
    input=input.split("\n");
    for(let i=0;i<input.length;i++){
        input[i]=input[i].split(" ");
    }
    
    let answer=-1;
    for(let i=0;i<1000;i++){
        if(i.length!=input[0][0])continue;
        let flag=true;
        for(let j=0;j<input[0][1];j++){
            if(i[input[j+1][0]-1]!=input[j+1][1])flag=false;
        }
        if(flag){
            answer=i;
            break;
        }
    }
    
    console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));