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が0だと-1
    val maxS = scs.maxBy { it.s == 1 }
    if (n != 1 && (maxS == null || maxS.c == 0)) {
        println(-1)
        return
    }
    // sが重複してるものがあると-1
    scs.groupBy { it.s }
        .values
        .find {
            it.size > 1 && it.distinct().size != 1
        }?.let {
            println(-1)
            return
        }
    val value = 1.until(n + 1).fold(0, { a, b ->
        a * 10 + (scs.find { it.s == b }?.c ?: 0)
    })

    println(value)
}
