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;
      int[] a = new int[N];
      int[] b = new int[N];

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

      int countMax = 0;
      // iテ」ツ?ッティツェツ佚」ツ??、ツコツコテヲツ閉ーテ」ツ??
      for (int i = 0; i <= 100001; i++)
      {
        int count = 0;
        for (int j = 0; j < N; j++)
        {
          // ティツ?ェテ・ツ按?」ツつづ・ツ?・テ」ツつ古」ツ?ヲティツィツアテ」ツ?療」ツ?ヲテ」ツつづ」ツつ嘉」ツ?暗」ツつ凝」ツ??
          if (a[j] <= i + 1 && i + 1 <= b[j])
          {
            count++;
          }
        }

        if (i <= count)
        {
          countMax = Math.Max(countMax, 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();
    }
  }
}