fun main(args: Array<String>) {
    data class SC(val s: Int, val c: Int)
    val (n, m) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val scs = 0.until(m).map {
        val sc = readLine()?.split(" ")?.map(String::toInt) ?: return
        SC(sc[0], sc[1])
    }
    // sが重複してるものがあると-1
    scs.groupBy { it.s }
        .values
        .find {
            it.size > 1 && it.distinct().size > 1
        }?.let {
            println(-1)
            return
        }
    // s=1が0だと-1
    val maxS = scs.find { it.s == 1 }
    if (n > 1 && (maxS?.c == 0)) {
        println(-1)
        return
    }
    val value = 1.until(n + 1).fold(0, { a, b ->
        a * 10 + (scs.find { it.s == b }?.c ?: if (n > 1 && b == 1) {
            1
        } else {
            0
        })
    })

    println(value)
}
