// Arup Guha
// 2/25/2018
// Solution to 2018 Januarty USACO Silver Problem: Lifeguards

import java.util.*;
import java.io.*;

public class lifeguards {

	public static int n;
	public static int k;
	public static int[] on;
	public static int[] off;

	public static void main(String[] args) throws Exception {

		// Read the data, just store when a lifeguard starts and ends.
		BufferedReader stdin = new BufferedReader(new FileReader("lifeguards.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		n = Integer.parseInt(tok.nextToken());
		on = new int[n];
		off = new int[n];

		// Store the interval information here.
		TreeSet<Integer> set = new TreeSet<Integer>();
		for (int i=0; i<n; i++) {
			tok = new StringTokenizer(stdin.readLine());
			on[i] = Integer.parseInt(tok.nextToken());
			off[i] = Integer.parseInt(tok.nextToken());
			set.add(on[i]);
			set.add(off[i]);
		}

		// Store a look up table from unique values from x's to id.
		int id = 0;
		TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();

		// Also build list of gaps.
		ArrayList<Integer> gaps = new ArrayList<Integer>();
		int prev = 0;
		boolean iter = false;
		while (set.size() > 0) {
			int next = set.pollFirst();
			map.put(next, id++);
			if (iter) gaps.add(next-prev);
			prev = next;
			iter = true;
		}

		// Store frequencies of on and off events at each unique point.
		int[] freq = new int[map.size()];
		for (int i=0; i<n; i++) {
			freq[map.get(on[i])]++;
			freq[map.get(off[i])]--;
		}

		// Make cumulative frequency.
		for (int i=1; i<freq.length; i++)
			freq[i] += freq[i-1];

		// Stores # of minutes in each interval that has exactly 1 lifeguard.
		// Also cumulative frequency.
		int[] onlyOne = new int[map.size()];

		// Calculate total time covered by all.
		int max = 0;
		for (int i=0; i<freq.length-1; i++) {

			// Adds into total sum.
			if (freq[i] > 0) max += gaps.get(i);

			// Add into interval with only one.
			onlyOne[i+1] = onlyOne[i];
			if (freq[i] == 1) onlyOne[i+1] += gaps.get(i);
		}

		int res = 0;

		// Now, try taking out each lifeguard.
		for (int i=0; i<n; i++) {

			// These are boundaries.
			int left = map.get(on[i]);
			int right = map.get(off[i]);

			// Here is what gets subbed out when we take out lifeguard i.
			int sub = onlyOne[right] - onlyOne[left];

			// Take the best.
			res = Math.max(res, max-sub);
		}

		// Ta da!
		PrintWriter out = new PrintWriter(new FileWriter("lifeguards.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}