object Main {
  def main(args:Array[String]) {
    val read = readLine().split(' ').map(_.toInt)
    var N = read(0)
    var M = read(1)
    var ans = 0
    var anslist = Array.fill(N)(-1)
    for(i <- 0 until M) {
      var sc = readLine().split(' ').map(_.toInt)
      if(sc(0) == 1 && sc(1) == 0) ans = -1
      else if(anslist(sc(0) - 1) == -1 || anslist(sc(0) - 1) == sc(1)) anslist(sc(0) - 1) = sc(1)
      else ans = -1
    }
    if(ans != -1) {
      var ind = 0
      for(i <- anslist.size - 1 to 0 by -1) {
        if(i == 0) anslist(i) = 1
        else if(anslist(i) == -1) anslist(i) = 0
        ans += anslist(ind) * math.pow(10, i).toInt
        ind += 1
      }
    }
    println(ans)
  }
}
