import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val s = (0 until m).map {
        sc.nextInt() - 1 to sc.nextInt()
    }

    println(abc157c(n, s))
}

private fun abc157c(n: Int, sc: List<Pair<Int, Int>>): Int {
    val scs = sc.sortedBy { it.first }
    val start = when (n) {
        2 -> 10
        3 -> 100
        else -> 0
    }
    val end = when (n) {
        2 -> 99
        3 -> 999
        else -> 9
    }

    for (i in start..end) {
        var ok = true
        for (sci in scs) {
            val s = sci.first
            val c = sci.second
            val istr = i.toString()
            if (istr.get(s).toString() != c.toString()) {
                ok = false
                break
            }
        }
        if (ok) return i
    }

    return -1
}