
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 { null as Int? }.toMutableList()
    
    for((s, c) in sc_map) {
        digit_list[s- 1] = c
    }
    if(N == 1) {
        (digit_list[0]?: 0).run(::println)
        return
    } else {
        var is_error = false 
        digit_list[0]?.run {
            if(this == 0) {
                println(-1)
                is_error = true
            }
        }
        if(is_error) {
            return
        }
    }
    for( i in 0 until digit_list.size) {
        if(digit_list[i] == null) {
            digit_list[i] = if(i == 0) {1} else {0}
        }
    }

    digit_list.joinToString("").toInt().let {
        val s = it.toString()
        s
    }.run(::println)
}