"use strict"
function main(arg) {
    var data = arg.trim().split("\n")
    var n = data.shift().split(" ").map(Number)[0]
    data = data.filter(function (x, i, self) {
        return self.indexOf(x) === i;
    })
    data = data.map(e => {
        e = e.split(" ").map(Number)
        e[0] -= 1
        return e
    })
    
    var ans = solve(data, n)
    
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function solve(data, n) {
    var N = new Array(n).fill(null)
    for (var i = 0; i < data.length; i++) {
        var key = data[i][0]
        var value = data[i][1]
        if (N[key] !== null) {
            return -1
        }
        N[key] = value
    }
    // var iniFlg = true
    for (var i = 0; i < N.length; i++) {
        if (N[i] === null) {
            if (i === 0) {
                N[i] = 1
            } else {
                N[i] = 0
            }
        }
        // iniFlg = false
    }
    if (N.join('') === String(Number(N.join('')))) {
        return Number(N.join(''))
    }
    return -1
}