"use strict";
const main = arg => {
    const input = arg.trim().split("\n");

    const N = parseInt(input[0].split(" ")[0]);
    const M = parseInt(input[0].split(" ")[1]);
    let s = {}
    let flag = true
    for (let i = 1; i <= M; i++) {
        let digit = parseInt(input[i].split(" ")[0])
        let num = parseInt(input[i].split(" ")[1])
        if (s[digit] && s[digit] !== num) {
            flag = true
            break
        } else if (N >= 2 && digit === 1 && num == 0) {
            flag = true
            break
        } else {
            s[digit] = num
        }
    }
    if (flag) {
        let ans = new Array(N).fill(0)
        if (N > 1) ans[0] = 1
        for (let key of Object.keys(s)) {
            ans[key - 1] = s[key]
        }
        console.log(Number(ans.join("")))
    } else {
        console.log('-1')
    }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  