// Arup Guha
// 1/28/2018
// Solution to Jan 2018 USACO Bronze Problem: Lifeguards

// I try something here that's pretty slow, but easy to come up with...
// Something that a bronze level student ought to be able to understand.

import java.util.*;
import java.io.*;

public class lifeguards_bronze {

	final public static int MAX = 1000;

	public static void main(String[] args) throws Exception {

		// Read the data.
		Scanner stdin = new Scanner(new File("lifeguards.in"));
		int n = stdin.nextInt();

		guard[] list = new guard[n+1];
		for (int i=0; i<n; i++) {
			int s = stdin.nextInt();
			int e = stdin.nextInt();
			list[i] = new guard(s,e);
		}

		int res = 0;

		// This is who we're skipping.
		for (int skip = 0; skip<n; skip++) {

			boolean[] covered = new boolean[MAX];

			// Go through each.
			for (int i=0; i<n; i++) {

				// Skip this guard.
				if (i == skip) continue;

				// Mark each minute this guard covers.
				for (int j=list[i].s; j<list[i].e; j++)
					covered[j] = true;
			}

			// Count all covered minutes.
			int cnt = 0;
			for (int i=0; i<MAX; i++)
				if (covered[i])
					cnt++;

			// Update our result, if necessary.
			res = Math.max(res, cnt);
		}

		// Ta da!
		PrintWriter out = new PrintWriter(new FileWriter("lifeguards.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}

class guard {

	public int s;
	public int e;

	public guard(int mys, int mye) {
		s = mys;
		e = mye;
	}
}