fun main(args: Array<String>) {
  val (N, M) = readInts()
  val SC = (1..M).map { readInts() }

  var beginNum = Math.pow(10.0, (N - 1).toDouble()).toInt()
  val endNum = beginNum * 10
  if (beginNum == 1) beginNum = 0
  for (n in beginNum until endNum) {
    val d = n.toString().map { it.toString().toInt() }
    var f = true
    for (i in 0 until M) {
      val (S, C) = SC[i]
      if (d[S - 1] != C) f = false
    }
    if (f) {
      println(n)
      return
    }
  }
  println(-1)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }
