fun main(args: Array<String>) = asakatsu0404c()

fun asakatsu0404c() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val scList = (1..m).map { readLine()!!.split(' ').map { it.toInt() } }
        .map { it[0] to it[1] }

    for (i in 0..999) {
        if (i.toString().length != n) continue
        if (scList.all { Character.getNumericValue(i.toString()[it.first - 1]) == it.second }) {
            return println(i)
        }
    }

    println(-1)
}
