import scala.collection.immutable.HashSet

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M = sc.nextInt()
  val pairs = HashSet.fill(M)(sc.nextInt() - 1 -> sc.next().toCharArray.head)
  val isMatched = (i: String) => pairs.forall { case (s, c) => i(s) == c }
  println {
    math.pow(10, N - 1).toInt.to(("9" * N).toInt).collectFirst {
      case i if isMatched(i.toString) => i
    }.getOrElse(-1)
  }
}
