object Main extends App{
  import scala.io.StdIn._
  val Array(n,m)=readLine().split(" ").map(_.toInt)
  var ans=new Array[Int](n);var a:Int=_
  var s=new Array[Int](n);var flag=true;var f:Array[Int]=_
  for{i <- (0 until(m))}{
    f=readLine().split(" ").map(_.toInt)
    s(f(0)-1)=f(1)
    if(s(f(0)-1)!=f(1)){
      flag=false
    }
  }
  if(s(0)!=0) {
    for {i <- (0 until (n))} {
      a *= 10
      ans(i) = s(i)
      a += ans(i)
    }
  }else{
    flag=false
  }
  println(if(flag)a else -1)
}