"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 = {}
    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){
            console.log('-1')
            return
        } else if (digit === 1 && num == 0){
            console.log('-1')
            return
        } else {
            s[digit] = num
        }
    }
    let ans = new Array(N).fill(0)
    if(N==1){
        console.log(s[1])
        return
    }
    ans[0] = 1
    for(let key of Object.keys(s)){
        ans[key-1] = s[key]
    }
    console.log(Number(ans.join("")))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  