import * as fs from 'fs';
// main
function main(input: string[]) {
    // param
    let n: number = 0;
    let m: number = 0;
    let sm: number[] = [];
    let cm: number[] = [];
    let ans: number = 0;
    // init
    [n, m] = input.shift().split(" ").map(x => Number(x));
    for (let mx = 0; mx < m; mx++) {
        [sm[mx], cm[mx]] = input[mx].split(" ").map(x => Number(x));
    }
    // solve
    var wn = new Array(n).fill(-1);
    for (let mx = 0; mx < m; mx++) {
        if (0 <= wn[sm[mx] - 1] && wn[sm[mx] - 1] != cm[mx]) {
            ans = -1;
            break;
        }
        wn[sm[mx] - 1] = cm[mx];
    }
    if (ans == 0) {
        for (let nx = 0; nx < n; nx++) {
            if (wn[nx] == -1) {
                wn[nx] = (nx == 0) ? 1 : 0;
            }
        }
    }
    if (wn[0] == 0) {
        ans = -1;
    }
    if (ans != -1) {
        ans = Number(wn.map(x => String(x)).join(""));
    }
    // answer
    console.log(ans);
}
// entrypoint
function entrypoint() {
    try {
        // linux
        let input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        // windows
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            let input = lines;
            main(input);
        });
    }
}
entrypoint();
