fun main(args: Array<String>) {
    val (n, m) = readIntList()
    val a = Array(n) { -1 }
    repeat(m) {
        val (s, c) = readIntList()
        if (a[s - 1] != -1 && a[s - 1] != c) {
            println(-1)
            return
        }
        a[s - 1] = c
    }
    var ans = ""
    for (i in 0 until n) {
        ans += if (a[i] == -1) 0 else a[i]
    }

    if (ans.length > 1 && ans[0] == '0') {
        println(-1)
        return
    }
    if (ans.toInt().toString().length != n) {
        println(-1)
        return
    }
    println(ans.toInt())

}

// 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)