fun main(args: Array<String>){
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var f = true
    val number = IntArray(n){0}
    repeat(m){
        val (s, c) = readLine()!!.split(" ").map { it.toInt() }
        if(number[s-1] == 0 || number[s-1] == c){
            number[s-1] = c
        }else{
            f = false
        }
    }
    val ans = number.joinToString(separator = "").toInt()

    if(ans.toString().length == n && f){
        println(ans)
    }else{
        println(-1)
    }
}