#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool comp(int a, int b) {
	return a > b;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    
    vector <int> men;
    vector <int> women;
    
    for (int i = 0; i < n; i++) {
    	bool o;
    	int height;
    	cin >> o >> height;
    	
    	if (o == 0) {
    		men.push_back(height);
    	} else {
    		women.push_back(height);
    	}
    }
    
    sort(men.begin(), men.end(), comp);
    sort(women.begin(), women.end(), comp);
    
    int ans = -1;
    
    for (int i = 0; i < max((int)men.size() - 1, 0); i++) {
    	ans = max(ans, men[i] - men[i + 1]);
    }

	if (men.size() > 0 && women.size() > 0) {
		ans = max(ans, abs(men[men.size() - 1] - women[0]));
	}

	for (int i = 0; i < max((int)women.size() - 1, 0); i++) {
    	ans = max(ans, women[i] - women[i + 1]);
    }
    
    cout << ans;
    
    return 0;
    
}