import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val s = (0 until m).map {
        sc.nextInt() - 1 to sc.nextInt()
    }

    println(abc157c(n, s))
}

private fun abc157c(n: Int, sc: List<Pair<Int, Int>>): Int {
    val num = IntArray(n)
    for (sci in sc) {
        val s = sci.first
        val c = sci.second
        num[s] = c
    }

    var ok = true
    for (sci in sc) {
        val s = sci.first
        val c = sci.second
        if (num[s] != c) {
            ok = false
            break
        }
        if (s == 0 && c == 0) {
            ok = false
            break
        }
    }

    if (ok) {
        var ans = ""
        for (ni in num) {
            ans += ni.toString()
        }
        return ans.toInt()
    }

    return -1
}