import scala.io.StdIn._

object Main extends App {


  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val hintArr = Array.fill(m)(readLine().split(" ").map(_.toInt))

  def solve(): Int = {
    val default = Map.empty[Int, Int]
    val digitAndNumMap = hintArr.foldLeft(default) { (acc, hint) =>
      acc.get(hint(0)) match {
        case Some(v) =>
          if(v == hint(1)) acc else return -1
        case None =>
          if(n != 1 && hint(0) == 1 && hint(1) == 0) return -1
          else acc.updated(hint(0), hint(1))
      }
    }
    (1 to n).map { i =>
      if(i == 1) digitAndNumMap.getOrElse(i, 1)
      else digitAndNumMap.getOrElse(i, 0)
    }.mkString("").toInt
  }

  println(solve())

}

