fun main(args: Array<String>) {
    val nm = readLine()!!.split(" ").map(String::toInt)

    var ans = arrayOfNulls<String>(nm[0])
    for (i in 1.. nm[0]) {
        ans[i -1] = " "
    }
    var fail = false
    for (i in 1.. nm[1]) {
        val sc = readLine()!!.split(" ")

        if (ans[sc[0].toInt()-1] == " " || ans[sc[0].toInt()-1] == sc[1]) {
            ans[sc[0].toInt()-1] = sc[1]
        } else {
            fail = true
        }
    }

    if (fail) {
        println("-1")
    } else {
        if (ans[0] == "0") {
            if (nm[0] == 1 ) println("0")
            else  println("-1")
        } else {
            for (i in 1..nm[0]) {
                if (ans[i -1] == " ") {
                    if (i==1) {
                        if (nm[0] == 1 ) ans[i -1] = "0"
                        else  ans[i -1] = "1"
                    } else { ans[i -1] = "0" }
                }
                print(ans[i -1])
            }
            println()
        }
    }
}
