using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			LR[] lrs = new LR[n];
			for (int i = 0; i < n; i++) {
				long l = cin.Long();
				long r = cin.Long();
				lrs[i] = new LR(l, r);
			}

			int maxIndex = 0;
			long maxCount = 0;
			for (int i = 0; i < n; i++) {
				long count = lrs[i].R - lrs[i].L + 1;
				if (count > maxCount) {
					maxIndex = i;
					maxCount = count;
				}
			}

			long remain = Count(lrs, maxIndex);
			long ans = maxCount + remain;

			int maxLIndex = 0;
			int minRIndex = 0;
			long minR = long.MaxValue;
			long maxL = -1;
			for (int i = 0; i < n; i++) {
				if (lrs[i].L > maxL) {
					maxLIndex = i;
					maxL = lrs[i].L;
				}

				if (lrs[i].R < minR) {
					minRIndex = i;
					minR = lrs[i].R;
				}
			}

			var diffsTemp = new List<LR>();
			for (int i = 0; i < n; i++) {
				if (i != maxLIndex && i != minRIndex) {
					diffsTemp.Add(new LR(Math.Max(0, minR - lrs[i].L + 1), Math.Max(0, lrs[i].R - maxL + 1)));
				}
			}

			var diffs = diffsTemp.OrderByDescending(x => x.L).ThenBy(x => x.R).ToArray();

			MultiSet<long> rs = new MultiSet<long>(diffs.Length);
			for (int i = 0; i < diffs.Length; i++) {
				rs.Add(diffs[i].R);
			}

			for (int i = 0; i <= diffs.Length; i++) {
				if (i != 0) {
					rs.Remove(diffs[i  - 1].R);
				}

				long count1 = i == 0
					? lrs[minRIndex].R - lrs[minRIndex].L + 1
					: diffs[i - 1].L;
				long count2 = i == diffs.Length
					? lrs[maxLIndex].R - lrs[maxLIndex].L + 1
					: rs.Min;

				ans = Math.Max(ans, count1 + count2);
			}

			Console.WriteLine(ans);
		}

		public static long Count(IReadOnlyList<LR> lrs)
		{
			if (lrs.Count == 0) {
				return 0;
			}

			long l = lrs[0].L;
			long r = lrs[0].R;
			for (int i = 1; i < lrs.Count; i++) {
				l = Math.Max(l, lrs[i].L);
				r = Math.Min(r, lrs[i].R);
				if (r < l) {
					return 0;
				}
			}

			return r - l + 1;
		}

		public static long Count(LR[] lrs, int exclude)
		{
			int first = exclude == 0 ? 1 : 0;
			if (lrs.Length <= first) {
				return 0;
			}

			long l = lrs[first].L;
			long r = lrs[first].R;
			for (int i = 1; i < lrs.Length; i++) {
				if (i == exclude) {
					continue;
				}

				l = Math.Max(l, lrs[i].L);
				r = Math.Min(r, lrs[i].R);
				if (r < l) {
					return 0;
				}
			}

			return r - l + 1;
		}

		public static long Count(LR[] lrs, int start, int end)
		{
			if (end - start <= 0) {
				return 0;
			}

			long l = lrs[start].L;
			long r = lrs[start].R;
			for (int i = 1; i < end; i++) {
				l = Math.Max(l, lrs[i].L);
				r = Math.Min(r, lrs[i].R);
				if (r < l) {
					return 0;
				}
			}

			return r - l + 1;
		}

		public struct LR
		{
			public long L { get; set; }
			public long R { get; set; }
			public LR(long l, long r)
			{
				L = l;
				R = r;
			}
		}
	}

	public class MultiSet<T> :
		IEnumerable<T>,
		System.Collections.IEnumerable,
		ICollection<T>,
		System.Collections.ICollection,
		IReadOnlyCollection<T>
	{
		private readonly SortedSet<T> set_;
		private readonly Dictionary<T, int> counts_ = new Dictionary<T, int>();

		public MultiSet(
			int capacity,
			IEnumerable<T> collection = null,
			IComparer<T> comparer = null)
		{
			counts_ = new Dictionary<T, int>(capacity);
			if (collection == null && comparer == null) {
				set_ = new SortedSet<T>();
			} else if (collection == null) {
				set_ = new SortedSet<T>(comparer);
			} else if (comparer == null) {
				set_ = new SortedSet<T>(collection);
			} else {
				set_ = new SortedSet<T>(collection, comparer);
			}
		}

		public IComparer<T> Comparer => set_.Comparer;
		public int Count { get; private set; }
		public T Max => set_.Max;
		public T Min => set_.Min;

		public bool IsReadOnly => false;

		object System.Collections.ICollection.SyncRoot
			=> (set_ as System.Collections.ICollection).SyncRoot;

		bool System.Collections.ICollection.IsSynchronized
			=> (set_ as System.Collections.ICollection).IsSynchronized;

		public bool Add(T item)
		{
			if (counts_.ContainsKey(item) == false) {
				counts_[item] = 1;
			} else {
				counts_[item]++;
			}

			set_.Add(item);
			++Count;
			return true;
		}

		public bool Remove(T item)
		{
			if (counts_.ContainsKey(item) == false) {
				return false;
			}

			counts_[item]--;
			Count--;
			if (counts_[item] == 0) {
				counts_.Remove(item);
				set_.Remove(item);
			}

			return true;
		}

		public void Clear()
		{
			counts_.Clear();
			Count = 0;
			set_.Clear();
		}

		public bool Contains(T item) => set_.Contains(item);

		public IEnumerator<T> GetEnumerator()
		{
			foreach (var s in set_) {
				for (int i = 0; i < counts_[s]; i++) {
					yield return s;
				}
			}
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
			=> GetEnumerator();

		void ICollection<T>.Add(T item) => Add(item);

		public void CopyTo(T[] array, int arrayIndex)
		{
			int index = arrayIndex;
			foreach (var s in set_) {
				for (int i = 0; i < counts_[s]; i++) {
					array[index] = s;
					++index;
				}
			}
		}

		void System.Collections.ICollection.CopyTo(Array array, int index)
		{
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 36164