import io.StdIn.readLine


object Main {

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readLine().split(' ').map(_.toInt)
    val points = for (i <- 1 to m) yield {
      val Array(x, y) = readLine().split(' ').map(_.toInt)
      (x - 1, y - 1)
    }

    val base = points.foldLeft(0) { (acc, p) => acc | (1 << (p._1 * n + p._2)) }

    val xxx = points.groupBy(_._2).map { case (k, v) => (k -> v.map(_._1)) }
    val zzz = points.groupBy(_._1).map { case (k, v) => (k -> v.map(_._2)) }

    println(base.toBinaryString)
    println(xxx)
    println(zzz)

    (0 to (n - 1)).foldLeft(base) { (acc, i) =>
      var a = acc
      val xxOpt = xxx.get(i)
      val zzOpt = zzz.get(i)
      (xxOpt, zzOpt) match {
        case (Some(xx), Some(zz)) => for (x <- xx; z <- zz) {
          println((z, x))
          a = a | (1 << (z * n + x))
        }
        case _ => ()
      }
      a
    }

    println(base.toBinaryString.count(_ == '1'))
  }

}
