import io.StdIn._

object ABC157C extends App {

  var range = Range.inclusive(0, 999).toArray

  val NM = readLine.split(" ").map(_.toInt)
  val N = NM(0)
  val M = NM(1)
  range = range.filter { n =>
    N match {
      case 1 => n < 10
      case 2 => n >= 10 && n < 100
      case 3 => n >= 100
    }
  }

  for (_ <- 0 until M) {
    val SC = readLine.split(" ").map(_.toInt)
    val S = SC(0)
    val C = SC(1)

    range = range.filter { n =>

      (N, S) match {
        case (3, 3) => n % 100 == C
        case (3, 2) => (n / 10) % 10 == C
        case (3, 1) => n / 100 == C

        case (2, 2) => n % 10 == C
        case (2, 1) => n / 10 == C

        case (1, 1) => n == C
        case _ => false
      }
    }
  }

  println( if(range.isEmpty) -1 else range(0))
}
