import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, m) = input.nextLine().split(" ").map(_.toInt)
      val ranges =
        1.to(m)
          .map { _ =>
            val Array(s, e) = input.nextLine().split(" ").map(_.toInt)
            (s, e)
          }

      var remainingRanges = ranges
      var count = 0
      while (remainingRanges.nonEmpty) {
        val (startCounts, endCounts) = (Array.fill(n)(0), Array.fill(n)(0))
        remainingRanges.foreach { case (s, e) =>
          startCounts(s - 1) += 1
          endCounts(e - 1) += 1
        }

        val values = Array.fill(n)(0)
        var overlaps = 0
        0.until(n).foreach { i =>
          overlaps += startCounts(i)
          overlaps -= endCounts(i)
          values(i) = overlaps
        }

        val max = values.max
        val i = values.indexOf(max)

        remainingRanges = remainingRanges.filterNot { case (s, e) =>
          s - 1 <= i && i < e - 1
        }

        count += 1
      }

      output.println(count)
    }

  }

}
