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() -> sc.nextInt())
  val map = pairs.toMap
  println {
    if (pairs.size == map.size && !(N != 1 && map.get(1).contains(0))) {
      1.to(N).foldLeft("")((acc, i) => acc + map.getOrElse(i, 0))
    } else {
      "-1"
    }
  }
}
