fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val S = IntArray(M)
    val C = IntArray(M)
    repeat(M) {
        val (s, c) = listOfInt()
        S[it] = s - 1
        C[it] = c
    }
    val min: Int
    val max: Int
    when (N) {
        1 -> { min = 0; max = 9 }
        2 -> { min = 10; max = 99 }
        3 -> { min = 100; max = 999 }
    }
    fun d2c(D: Int): IntArray {
        var n = D
        val a = IntArray(N)
        for (i in (0 until N).reversed()) {
            a[i] = n % 10
            n /= 10
        }
        return a
    }
    for (n in min .. max) {
        var ans = true
        val d = d2c(n)
        for (m in 0 until M) {
            if (d[S[m]] != C[m]) ans = false
        }
        if (ans) {
            println(n)
            return
        }
    }
    println(-1)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
