import io.StdIn._

object Main extends App {
  val NM = readLine.split(" ").map(_.toInt)
  val N = NM(0)
  val M = NM(1)

  val constraints = Range(0, M).map { _ =>
    val SC = readLine.split(" ").map(_.toInt)
    (SC(0), SC(1))
  }

  val ans = Range.inclusive(0, 999).find { n =>
    var keta = N
    var nx = n
    val ketaToDigit = Array.fill[Int](N)(0)

    ketaToDigit(keta - 1) = nx % 10
    while (nx >= 10) {
      keta -= 1
      nx /= 10
      ketaToDigit(keta - 1) = nx % 10
    }

    keta == 1 && constraints.forall { case (s, c) => ketaToDigit(s - 1) == c }
  }

  println(ans.getOrElse(-1))
}
