
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val sc = (1..M).map {
        val (s, c) = readLine()!!.split(" ").map(String::toInt)
        Pair(s, c)
    }

    val sc_map: MutableMap<Int, Int> = mutableMapOf()
    for((s, c) in sc) {
        sc_map.get(s)?.run {
            if(this != c) {
                println("-1")
                return
            }
        }
        sc_map[s] = c
    }
    sc_map.keys.min()?.let { sc_map.get(it) }?.run {
        if(this == 0 && N >= 2) {
            println("-1")
            return
        }
    }


    for(n in 0..1000) {
        val s = ("000" + n.toString()).takeLast(3)
        if(sc_map.all {
            val (k, c) = it 
             (s[k - 1] - '0').toInt() == c 
             }) {
            println(n)
            return
        }
    }
    println(-1)
}