object Main extends App {
	val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	var map = Map[Int, Int]()
	var flg = true

	for(i<-0 until m){
		val Array(s, c) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		if(map.contains(s)){
			if(map(s) != c) flg = false
		}else{
			map += s->c
		}
	}

	if(flg){
		var ans = 1000

		for(x<-0 until 1000){
			val tp = x.toString.toList.toArray
			var flg1 = true

			if(tp.size == n){
				for(y<-map){
					val (s, c) = y
					if(tp(s-1).toString != c.toString) flg1 = false
				}

				if(flg1){
					ans = math.min(ans, x)
				}
			}
		}

		if(ans == 1000) println(-1)
		else println(ans)
	}else{
		println(-1)
	}

}