#include <iostream>
using namespace std;

struct monitor
{
	long long width;
	long long height;
	void typeRes()
	{
		cin >> width;
		cin >> height;
	}
	void resetValues()
	{
		width=0;
		height=0;
	}
};
const int MAXN=100000;
int n;
monitor monitors[MAXN];

void getInput()
{
	cin >> n;
	for (int i=0; i<n; ++i) 
	{
		monitors[i].typeRes();
		//cout << monitors[i].width << " " << monitors[i].height << endl;
	}
}
int getMax()
{
	int max=0;
	for (int i=0; i<n; ++i)
	{
		if (monitors[i].width>max)
		{
			max=monitors[i].width;
		}
	}
	return max;
}
int maxWidthRes;
void findMaxRes()
{
	for (int i=0; i<n; ++i)
	{
		for (int j=i+1; j<n; ++j)
		{
			while (monitors[j].height==monitors[i].height)
			{
				monitors[i].width+=monitors[j].width;
				monitors[j].resetValues();
				swap(monitors[n-1].width,monitors[j].width);
				swap(monitors[n-1].height,monitors[j].height);
				--n;
				//cout << monitors[i].width << " " << monitors[i].height << endl;
				//cout << monitors[j].width << " " << monitors[j].height << endl; 
			}
		}
	}
	maxWidthRes=getMax();
}
void showOutput()
{
	cout << maxWidthRes;
}
int main()
{
	getInput();
    findMaxRes();
    showOutput();		
	
	cout << "\n";
	return 0;
}
