fun main(args: Array<String>) = println(run {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val sm = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }

    val conditions = sm.groupBy { it[0] }.mapValues { it.value.distinct() }
    if (conditions.any { it.value.size > 1 }) return@run -1
    val ans = CharArray(n){ '0' }
    conditions.mapValues { it.value.first()[1] }.forEach {
        ans[it.key-1] = it.value.toString().first()
    }
    if (ans[0] == '0') -1
    else ans.joinToString("")
})