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]
    }
    val start = if (N == 1) 0 else Math.pow(10.0, N-1.0).toInt()
    for (x in start 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)
}