
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val sc = (1..M).map {
        val (s, c) = readLine()!!.split(" ").map(String::toInt)
        Pair(s, c)
    }
    val sc_map: MutableMap<Int, Int> = mutableMapOf()
    for((s, c) in sc) {
        sc_map.get(s)?.run {
            if(this != c) {
                println("-1")
                return
            }
        }
        sc_map[s] = c
    }

    val digit_list = (1..N).map { 0 }.toMutableList()
    
    for((s, c) in sc_map) {
        digit_list[s- 1] = c
    }

    digit_list.joinToString("").toInt().let {
        val s = it.toString()
    
        if(s.length != N && s.substring(0, listOf(N - s.length + 1, s.length).min()!!).toInt() == 0) {
            "-1"
        } else {
            s
        }
    }.run(::println)
}