import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()
    val M = scn.nextInt()
    var A = IntArray(N+1)

    if(M==0 && N==1) {
        println(0)
        return
    }

    for(i in 1..N){
        A[i] = -1
    }

    for(i in 1..M){
        var s = scn.nextInt()
        var c = scn.nextInt()
        if(A[s] != -1 && A[s] != c) {
            println(-1)
            return
        }

        A[s] = c
    }

    var result = ""
    for(i in 1..N){
        if(A[i]==-1) A[i] = 0
        result += A[i].toString()
    }

    if(result.toInt().toString().length == N) {
        println(result)
    }else{
        println(-1)
    }

}