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) - 1, SC(1))
  }

  val ans = Range.inclusive(0, 999).find { n =>
    val ketaToDigit = n.toString.map(_.toInt - 48)

    ketaToDigit.length == N &&
      constraints.forall { case (s, c) => ketaToDigit(s) == c }
  }

  println(ans.getOrElse(-1))
}
