fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val a = IntArray(n + 1) { -1 }

    var error = false

    repeat(m) {
        val (s, c) = readLine()!!.split(' ').map { it.toInt() }
        if (a[s] == -1) a[s] = c
        if (a[s] != c) {
            error = true
            return@repeat
        }
    }

    for (i in 1..n) {
        if (n >= 2 && i < n && a[i] == 0) {
            error = true
            break
        }
        if (a[i] < 0) {
            a[i] = 0
        }
    }

    println(if (error) -1 else a.slice(1..n).joinToString("").toInt())
}