import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m) = in.readLine().split("\\s").map(_.toInt)
    val result = Array.ofDim[Int](n)

    val scs = (for {
      _ <- 0 until m
    } yield {
      in.readLine().split("\\s").map(_.toInt)
    }).sortWith {
      case (sc1, sc2) => sc1(0) < sc2(0)
    }

    if (scs.groupBy(_ (0)).exists {
      case (_, scs) => scs.map(_ (1)).distinct.size != 1
    }) {
      out.println("-1")
    } else {
      for {
        i <- 0 until m
      } {
        result(scs(i)(0) - 1) = scs(i)(1)
      }

      if (result(0) == 0) {
        if (n == 1) {
          out.println(0)
        } else {
          out.println(-1)
        }
      } else {
        out.println(result.mkString(""))
      }
    }

    out.flush()
  }
}
