#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <array>
#include <bitset>

long long mod = 1e9 + 7;
class Mint
{
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a)
  {
    x = a % mod;
    while (x < 0)
    {
      x += mod;
    }
  };
  Mint &operator+=(const Mint &a)
  {
    x += a.x;
    x %= mod;
    return *this;
  }
  Mint &operator-=(const Mint &a)
  {
    x += (mod - a.x);
    x %= mod;
    return *this;
  }
  Mint &operator*=(const Mint &a)
  {
    x *= a.x;
    x %= mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = Mint(2).pow(n);
  Mint pow(long long n) const
  {
    if (n == 0)
      return Mint(1);
    Mint y = pow(n >> 1); // pow(n/2)を計算する
    y *= y;
    if (n % 2 == 1)
      y *= *this;
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const
  {
    return a.pow(mod - 2);
  }

  Mint &operator/=(const Mint &a)
  {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator+(Mint &a) const
  {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator-(Mint &a) const
  {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator*(Mint &a) const
  {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator/(Mint &a) const
  {
    Mint y(*this);
    y /= a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const
  {
    Mint y = Mint(1);
    Mint iy = Mint(1);
    Mint one = Mint(1);
    // 割り算の演算は時間がかかるので最後に1度だけ行うようにすること
    for (Mint i(0); (i.x) < k; i.x++)
    {
      y *= (n - i);
      iy *= (i + one);
    }
    return y / iy;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const
  {
    Mint y(1);
    for (Mint i(0); (i.x) < k; i.x++)
    {
      y *= (n - i);
    }
    return y;
  }
};

class UnionFind
{
private:
  int n;
  std::vector<int> parent;

public:
  UnionFind(int num) : n(num)
  {
    parent = std::vector<int>(n);
    for (int i = 0; i < n; i++)
    {
      parent[i] = i;
    }
  }
  int GetRoot(int i)
  {
    int n = i;
    while (parent[n] != n)
    {
      n = parent[n];
    }
    parent[i] = n;
    return n;
  }

  bool SameGroup(int n, int m)
  {
    n = this->GetRoot(n);
    m = this->GetRoot(m);
    return n == m;
  }

  bool Unite(int n, int m)
  {
    n = this->GetRoot(n);
    m = this->GetRoot(m);
    if (n == m)
      return false;
    parent[n] = m;
    return true;
  }
};

int getgcd(int a, int b)
{
  int max = std::max(a, b);
  int min = std::min(a, b);
  if (min == 0)
    return max;
  return getgcd(min, max % min);
}

Mint mynCk(int n, int k)
{
  if (2 * k > n)
    return mynCk(n, n - k);
  Mint retval(1);
  Mint iretval(1);
  for (int i = 0; i < k; i++)
  {
    retval *= Mint(n - i);
  }
  for (int i = 1; i <= k; i++)
  {
    iretval *= Mint(i);
  }
  return retval / iretval;
}
int node[400000];
int depth;
int leafnum;
void update(int i, int value) {
  int index = i + leafnum;
  node[index] = value;
  while(index>0) {
    index /= 2;
    node[index] = std::max(node[index*2+1], node[index*2]);
  }
  return;
}

int getmax() {
  return node[1];
}

int main()
{
  int N;
  std::cin >> N;
  leafnum=1;
  depth=1;
  while(leafnum<N) {
    leafnum *= 2;
    depth++;
  }
  std::vector<long long > L(N), R(N);
  long long Lmax = -1, Rmin = 1001001001;
  int LmaxID, RminID;
  for (int i=0; i<N; i++) {
    std::cin >> L[i] >> R[i];
    if (Lmax<L[i]) {
      Lmax = L[i];
      LmaxID = i;
    }
    if (Rmin>R[i]) {
      Rmin = R[i];
      RminID = i;
    }
  }
  long long ans = 0;
  if (LmaxID == RminID) {
    ans = Rmin-Lmax+1;
    long long othermax = 0;
    for (int i=0; i<N; i++) {
      if (i==LmaxID) continue;
      othermax = std::max(othermax, R[i]-L[i]+1);
    }
    ans += othermax;
  } else {
    // Case 1: LmaxID & RminID are in the same group
    long long ans2 = 0;
    for (int i=0; i<N; i++) {
      if (i==LmaxID || i==RminID) continue;
      ans2 = std::max(ans2, R[i]-L[i]+1);
    }
    ans2 += std::max(R[RminID]-L[LmaxID]+1, (long long)0);
    ans = std::max(ans, ans2);
    // printf("Case1: ans=%lld\n", ans2);

    // Case 2: LmaxID & RminID are in the different group
    std::vector<std::pair<long long, int > > solver;
    for (int i=0; i<N; i++) {
      if (i==LmaxID || i==RminID) continue;
      solver.push_back(std::make_pair(R[i], i));
    }
    std::sort(solver.rbegin(), solver.rend());
    for (int i=0; i<N; i++) {
      if (i==LmaxID) continue;
      update(i, L[i]);
    }
    long long g1 = R[LmaxID]-L[LmaxID] + 1;
    long long g2 = std::max(R[RminID] - getmax() + 1, (long long)0);
    // printf("g1=%lld, g2=%lld\n", g1, g2);
    ans2 = g1+g2;
    for (auto &entry: solver) {
      g1 = std::max(entry.first - L[LmaxID] + 1, (long long)0);
      update(entry.second, 0);
      int max = getmax();
      g2 = std::max(R[RminID] - max + 1, (long long)0);
      // printf("g1=%lld, g2=%lld\n", g1, g2);
      ans2 = std::max(ans2, g1+g2);
      

    }
    ans = std::max(ans, ans2);
    // printf("Case1: ans=%lld\n", ans2);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 6944