fun main(args: Array<String>) {
    val (n, m) = readIntList()
    var a = Array(n) { -1 }

    repeat(m) {
        val (s, c) = readIntList()
        if (a[s - 1] != -1 && a[s - 1] != c) {
            println(-1)
            return
        }
        if (s > n) {
            println(-1)
            return
        }
        a[s - 1] = c
    }

    var ans = ""
    for (i in 0 until n) {
        ans += if (a[i] == -1) 1
        else a[i]
    }

    for (i in 1..999) {
        if (i.toString().length != n) continue
        if (i.toString() == ans) {
            println(i)
            return
        }
    }

    println(-1)
    return
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)