object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val reds, blues = List.fill(n)((sc.nextInt(), sc.nextInt()))
  val e = for {
    ((a, b), i) <- reds.zipWithIndex
    ((c, d), j) <- blues.zipWithIndex
    if a < c && b < d
  } yield (i, j)

  println(maximumMatching(n, n, e))

  def maximumMatching(n: Int, m: Int, e: Seq[(Int, Int)]): Int = {
    val adj = Array.fill(n)(List[Int]())
    for ((u, v) <- e) {
      adj(u) ::= v
    }

    val pair = Array.fill(m)(-1)

    def find(u: Int): Boolean = {
      val visited = Array.fill(m)(false)

      def dfs(u: Int): Boolean = {
        adj(u).find { v =>
          if (!visited(v)) {
            visited(v) = true
            pair(v) == -1 || dfs(pair(v))
          } else {
            false
          }
        } match {
          case Some(v) =>
            pair(v) = u
            true
          case None => false
        }
      }

      dfs(u)
    }

    (0 until n).count(find)
  }
}
