function Main(input) {
    var N = parseInt(input[0].split(/\s/)[0], 10);
    var M = parseInt(input[0].split(/\s/)[1], 10);
    var s = input.slice(1).map(sc => sc.split(/\s/)[0]);
    var c = input.slice(1).map(sc => sc.split(/\s/)[1]);
    
    var list = new Array(N);
    list.fill(-1);

    for (var i = 0; i < M; i++) {
        if (list[s[i] - 1] !== -1 && list[s[i] - 1] !== c[i]) {
            return console.log(-1);
        } else {
            list[s[i] - 1] = c[i];
        }
    }

    var result = '';

    for (var j = 0; j < N; j++) {
        if (j === 0) {
            if (list[j] === -1) {
                result += '1';
            } else if (list[j] === '0') {
                return console.log(-1);
            } else {
                result += `${list[j]}`;
            }
        } else if (list[j] === -1) {
            result += '0';
        } else {
            result += `${list[j]}`;
        }
    }

    console.log(result);
}

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