object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val n, m = sc.nextInt
	
	val a = Array.fill(n)(-1)
	var flag = true
	
	Seq.fill(m)((sc.nextInt-1, sc.nextInt)) foreach { case (s, c) =>
		if (a(s) != -1 && a(s) != c) flag = false
		a(s) = c
	}
	
	if (n >= 2 && a(0) == 0) flag = false
	if (n >= 2 && a(0) == -1) a(0) == 1
	
	pw.println( if (flag) a.map(e => if (e == -1) "0" else s"$e").mkString.toInt else -1 )
	pw.flush()
}