#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, book[3005];
struct e
{
int w, r;
}a[3005];
int dfs(int low)
{
int ans = 0;
for (int p=1;p<=n;p++)
{
if (!book[p]&&a[p].w>low)
{
book[p] = 1;
ans = max(ans, dfs(low+a[p].r)+a[p].w-low);
book[p] = 0;
}
}
return ans;
}
int main()
{
cin>>n;
for (int p=1;p<=n;p++)
{
cin>>a[p].w>>a[p].r;
}
cout<<dfs(0);
return 0;
}