#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main()
{
	ifstream cin("jumps.in");
	ofstream cout("jumps.out");
	int n;
	cin >> n;
	vector<int> a(n), t(n), id(n);
	for (int i = 0; i < n; i++)
		cin >> a[i] >> t[i], id[i] = i;

	long long ans = 1e18;
	int it = 0;
	do {
		long long cur = 0;
		for (int i = 0; i < n; i++)
			cur += (t[id[i]] <= i ? 0 : a[id[i]]);
		ans = min(ans, cur);
		cerr << it++;	
	} while(next_permutation(id.begin(), id.end()));
	cout << ans;                                     
}
