using System;
using System.Collections;
using System.IO;
using System.Linq;

namespace CompetitiveProgramming
{

  class Solve
  {

    const int INF = (int)(1e9) + 10;

    private void main()
    {
      int N = int.Parse(Console.ReadLine());
      int[] imos = new int[100003];
      int low = INF;

      for (int i = 0; i < N; i++)
      {
        int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        imos[ab[0]]++;
        imos[ab[1] + 1]--;
        low = Math.Min(low, ab[0]);
      }


      for (int i = 1; i < 100002; i++)
      {
        imos[i] += imos[i - 1];
      }

      int countMax = 0;
      for (int i = 0; i <= 100001; i++)
      {
        if (imos[i] >= i - 1)
        {
          countMax = Math.Max(countMax, imos[i]);
        }

      }
      Console.WriteLine(countMax);

    }


    public Solve()
    {
      Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
      main();
      Console.Out.Flush();
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      new Solve();
    }
  }
}