#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >>n;
	int a[n-1],b[n-1];
	int c[n-1],d[n-1];
	for (int i = 0; i<n-1;i++)
		{
			cin >>a[i]>>b[i];
			c[i] = a[i];
			d[i] = b[i];
		}
	sort (d,d+n-1);
	sort (c,c+n-1);
	int s[n-1];
	merge(c,c+n-1,d,d+n-1,s);
	cout <<(s[2*n-3] - s[1]) /2;
	return 0; 
}