import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A, B = map(N) { _ =>
      val x, y = sc.nextInt()
      (x, y)
    }

    Sorting.quickSort(B)(Ordering.by(_._1))
    val used = Array.ofDim[Boolean](N)

    def step(i: Int, cnt: Int): Int = {
      if (i == N) cnt
      else {
        val (bx, by) = B(i)
        val filtered = A.zipWithIndex.filter {
          case ((ax, ay), j) => !used(j) && ax < bx && ay < by
        }
        filtered.maxByOpt(_._1._2) match {
          case Some((_, j)) =>
            used(j) = true
            step(i + 1, cnt + 1)

          case None => step(i + 1, cnt)
        }
      }
    }
    val ans = step(0, 0)

    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) {
      f(i)
      i += 1
    }
  }

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    var i = 0
    while(i < n) {
      res(i) = f(i)
      i += 1
    }
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }
  }
}
