fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    fun pow10(n : Int) : Int {
        // special case
        if (n == 0) return 0

        var ret = 1
        repeat(n) {
            ret *= 10
        }
        return ret
    }
    val arr = Array(m) {
        readLine()!!.split(" ").map { it.toInt() }
    }
    for (i in pow10(n-1) until pow10(n)) {
        val s = i.toString()
        if (arr.all { list ->
                    val fst = list.component1()
                    val snd = list.component2().toString().first()
                    s[fst - 1] == snd
                }) {
            println(i)
            return
        }
    }
    println(-1)
}