fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    var s = "0".repeat(n).toCharArray()

    val map = mutableMapOf<Int, Int>()
    repeat(m) {
        val (si, ci) = readLine()!!.split(" ").map(String::toInt)
        if (map.contains(si)) {
            if (map.get(si) != ci) {
                println(-1)
                return
            }
        }
        map.put(si, ci)
    }
    for ((si, ci) in map) {
        s[si - 1] = ci.toString()[0]
    }

    val result = String(s)
    if (result != result.toInt().toString()) {
        println(-1)
        return
    }
    println(result)
}



