// Arup Guha
// 11/3/2018
// Solution to 2018 SER D1/D2 Problem: To Tell the Truth

import java.util.*;

public class truth {
		
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int[] low = new int[n];
		int[] high = new int[n];
		
		// Read in data.
		for (int i=0; i<n; i++) {
			low[i] = stdin.nextInt();
			high[i] = stdin.nextInt();
		}
		
		int ans = n;
		
		// Try each answer from max to min.
		while (ans >= 0) {
			
			// How many truth tellers with the answer ans.
			int real = 0;
			for (int i=0; i<n; i++)
				if (ans >= low[i] && ans <= high[i])
					real++;
			
			// This works, get out!
			if (ans == real) break;
			
			// Try next.
			ans--;
		}
		
		// Ta da! 
		System.out.println(ans);
	}
}
