fun main(args: Array<String>) = abc157c()

fun abc157c() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val scList = (1..m).map { readLine()!!.split(' ').map { it.toInt() }.let { Pair(it[0], it[1]) } }

    val number = IntArray(n) { -1 }

    for (sc in scList) {
        val (s, c) = sc
        if (number[s - 1] != -1 && number[s - 1] != c) return println(-1)
        number[s - 1] = c
    }

    if (n >= 2 && number[0] == 0) return println(-1)

    if (n >= 2 && number[0] == -1) number[0] = 1

    val answer = number.joinToString("") { (if (it == -1) 0 else it).toString() }

    println(answer)
}
