data class Sc(val s: Int, val c: Int) {
    constructor(sc: List<Int>): this(sc[0] - 1, sc[1])
}
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val SC = Array(M) { Sc(listOfInt()) }
    fun d2c(D: Int): List<Int> {
        if (D == 0) return intArrayOf(0).asList()
        var d = D
        val a = mutableListOf<Int>()
        while (d > 0) {
            a.add(d % 10)
            d /= 10
        }
        return a.reversed()
    }
    for (n in 0 .. 999) {
        val d = d2c(n)
        if (d.size != N) continue
        var ans = true
        for (m in 0 until M) {
            if (d[SC[m].s] != SC[m].c) ans = false
        }
        if (ans) {
            println(n)
            return
        }
    }
    println(-1)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }