fun main(args: Array<String>) = println(run {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val sm = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }

    val conditions = sm.groupBy { it[0]-1 }.mapValues { entry ->
        val values = entry.value.map { it -> it[1] }.distinct()
        if (values.size > 1) return@run -1
        values.first()
    }

    for (i in 0..999) {
        val str = i.toString()
        if (str.length != n) continue
        when {
            conditions.all { str[it.key].toString().toInt() == it.value } -> return@run i
        }
    }
    -1
})
