import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val t = Array(n) {-1}
    repeat(m) {
        val s = sc.nextInt() - 1
        val c = sc.nextInt()
        if (t[s] == -1) {
            t[s] = c
        } else if (t[s] != c) {
            println(-1)
            return
        }
    }
    for (i in 0..999) {
        val str = i.toString()
        if (str.length != n) {
            continue
        }
        var flg = true
        for (j in 0 until n) {
            if (t[j] == -1 || t[j] == str[j] - '0') {

            } else {
                flg = false
                break
            }
        }
        if (flg) {
            println(i)
            return
        }
    }
    println(-1)
}