fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val ans = IntArray(N + 1) { -1 }
    var ng = false
    repeat(M) {
        val (s, c) = readLine()!!.split(" ").map(String::toInt)
        if (ans[s] != -1 && ans[s] != c) ng = true
        ans[s] = c
    }
    if (ans[1] == -1) ans[1] = 1
    if (ng || ans[1] == 0) println(-1) else println(ans.drop(1).map { it.coerceAtLeast(0) }.joinToString(""))
}