import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val (n, m) = (0 until 2).map { sc.nextInt() }
    val mArr = Array<MutableList<Int>>(m) { mutableListOf() }
    repeat(m) {
        val tmpList = (0 until 2).map { sc.nextInt() }
        mArr[it] = tmpList.toMutableList()
    }
    var res = Array<Int>(m) { 0 }
    var res2 = ""
    //一つずつチェックする
    loop1@ for  (i in 0 until m) {
        for (j in 0 until 2) {
            if (res[mArr[i][0] - 1] == 0) {
                res[mArr[i][0] - 1] = mArr[i][1]
            } else if (res[mArr[i][0] - 1] == mArr[i][1]) {

            } else {
                res2 = "-1"
                break@loop1
            }
        }
    }
    if(n > 1 && res[0] == 0) {
        res2 = "-1"
    } else if (res2 != "-1") {
        repeat(m) {
            res2 += res[it]
        }
    }
    println(res2)
}