#include <iostream>

using namespace std;

#define N 8
#define FREE 0
#define NOT_FREE -1

bool BOARD[N][N] = { false };
int C_COL[N], C_ROW[N], C_DIAGONAL_L[2*N], C_DIAGONAL_R[2*N];

void printBoard() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (BOARD[i][j])
        if (C_ROW[i] != j) return;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cout << (C_ROW[i] == j ? 'Q' : '.');
    }
    cout << endl;
  }
}

void solve(int i) {
  if (i == N) {
    printBoard();
    return;
  }

  for (int j = 0; j < N; j++) {
    if (C_COL[j] == NOT_FREE ||
        C_DIAGONAL_L[i+j] == NOT_FREE ||
        C_DIAGONAL_R[i-j+N-1] == NOT_FREE
        ) continue;

    C_ROW[i] = j;
    C_COL[j] = C_DIAGONAL_L[i+j] = C_DIAGONAL_R[i-j+N-1] = NOT_FREE;

    solve(i+1);

    C_ROW[i] = C_COL[j] = C_DIAGONAL_L[i+j] = C_DIAGONAL_R[i-j+N-1] = FREE;
  }

  //cout << "no solution for input" << endl;
  
}

int main() {
  for (int i = 0; i < N; i++) {
    C_COL[i] = C_ROW[i] = FREE;
    C_DIAGONAL_L[i] = C_DIAGONAL_R[i] = FREE;
    C_DIAGONAL_L[2*i] = C_DIAGONAL_R[2*i] = FREE;
  }
  
  int k; cin >> k;
  while (k--) {
    int r, c; cin >> r >> c;
    BOARD[r][c] = true;
  }

  solve(0);
}
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
const int N = 1e5+5;
ll minnx[N];
int n;
struct node {
	ll l,r;
}a[N],s[N];

bool cmp(node a,node b){
	return a.l>b.l;
}

int main(){
	cin>>n;
	ll maxx=0,minn=1e17,maxlen=0;
	for(int i=1;i<=n;i++){
		cin>>a[i].l>>a[i].r;
		maxx=max(maxx,a[i].l);
		minn=min(minn,a[i].r);
		maxlen=max(maxlen,a[i].r-a[i].l+1);
	}
	ll ans1=maxlen+max(minn-maxx+1,0ll);
	for(int i=1;i<=n;i++){
		s[i].l=max(minn-a[i].l+1,0ll);
		s[i].r=max(a[i].r-maxx+1,0ll);
	}
	sort(s+1,s+n+1,cmp);
	minnx[n+1]=1e18;
	for(int i=n;i>=1;i--) minnx[i]=min(minnx[i+1],s[i].r);
	ll ans2=0;
	for(int i=1;i<=n-1;i++){
//		cout<<s[i].l<<" "<<s[i].r<<endl;
		ans2=max(ans2,s[i].l+minnx[i+1]);
//		cout<<ans2<<endl;
	}
//	cout<<ans1<<" "<<ans2<<endl;
	cout<<max(ans1,ans2)<<endl;
	
	return 0;
}