import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(' ').map { it.toInt() }
    val s = IntArray(M) { 0 }
    val c = IntArray(M) { 0 }
    for (i in 0 until M) {
        val sc = readLine()!!.split(' ').map { it.toInt() }
        s[i] = sc[0]
        c[i] = sc[1]
    }
    for (x in Math.pow(10.0, N-1.0).toInt() until Math.pow(10.0,N.toDouble()).toInt()) {
        val S = x.toString()
        var ok = true
        for (i in 0 until M) {
            if (S[s[i]-1].toString() != c[i].toString()) {
                ok=false
                break
            }
        }
        if (ok) {
            println(x)
            return
        }
    }
    println(-1)
}