import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

val reader by lazy { BufferedReader(InputStreamReader(System.`in`)) }

@Suppress("ReplaceJavaStaticMethodWithKotlinAnalog")
fun main(a: Array<String>) {
    val args = reader.readArgs()
    val n = args[0].toInt()
    val m = args[1].toInt()

    val list = (1..m).map { reader.readArgs() }.map { (it[0].toInt() - 1) to it[1].toInt() }
    val s = list.map { it.first }
    val c = list.map { it.second }

    val scMap = HashMap<Int, MutableList<Int>>()

    s.forEachIndexed { i, digit ->
        val cList = scMap.getOrPut(digit) { ArrayList() }
        cList.add(c[i])
        scMap[digit] = cList.distinct().toMutableList()
    }

    scMap.map { it.value }.forEach {
        if (it.size > 1) {
            println(-1)
            return
        }
    }

    val answer = (1..n).map { -1 }.toMutableList()

    scMap.forEach { answer[it.key] = it.value.first() }
    answer.forEachIndexed { digit, number ->
        if (number == -1) {
            answer[digit] = 0
        }
    }

    if (answer.size == 1) {
        println(answer[0])
        return
    }

    if (answer[0] == 0) {
        println(-1)
        return
    }

    if (answer.filterNot { it == 0 }.isEmpty()) {
        println(-1)
        return
    }

    println(answer.joinToString(""))
}

fun BufferedReader.readArgs() = readLine().split(" ")
fun BufferedReader.readInt() = readLine().toInt()
fun BufferedReader.readLong() = readLine().toLong()
fun BufferedReader.readChar() = readLine().toInt().toChar()
fun BufferedReader.readString() = readLine().toInt().toString()
