import java.math.BigInteger
import java.util.*

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val map = TreeMap<Int, Int>()
    (1..m).forEach {
        val s = sc.nextInt()
        val c = sc.nextInt()
        if (map.containsKey(s) && map[s] != c) {
            println(-1)
            return
        }
        map[s] = c
    }
    var r = 0
    if (map[1] != null) {
        if (n != 1 && map[1] == 0) {
            println(-1)
            return
        }
        r += map[1]!! * Math.pow(10.0, (n - 1).toDouble()).toInt()
    } else if (n != 1) {
        r += 1 * Math.pow(10.0, (n - 1).toDouble()).toInt()
    }
    if (n >= 2 && map[2] != null) {
        r += map[2]!! * Math.pow(10.0, (n - 2).toDouble()).toInt()
    }
    if (n >= 3 && map[3] != null) {
        r += map[3]!!
    }
    println(r)
}
