#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 100005;
const int MOD = 998244353;
const int MAX_VAL = N * 100;
int n;
struct Task {
int a, b;
};
int dp[2][2][50 * N];
struct DpState {
int i, j, k;
DpState(int _i, int _j, int _k) {
i = _i;
j = _j;
k = _k;
}
};
queue<DpState> que;
set<int> state_set;
int main() {
memset(dp, MAX_VAL, sizeof(dp));
while (cin >> n) {
Task task[100];
for (int i = 1; i <= n; i++) {
scanf("%d%d", &task[i].a, &task[i].b);
}
int ans = MAX_VAL;
state_set.clear();
que.push(DpState(0, 0, 0));
dp[0][0][0] = 0;
state_set.insert(0);
while (!que.empty()) {
DpState state = que.front();
que.pop();
int i = state.i, j = state.j, k = state.k;
if (i == n) {
ans = min(ans, dp[i & 1][j][k]);
continue;
}
if (j == 0) {
// use a
{
int _i = i + 1, _j = j, _k = k + task[i + 1].a;
int state = (_i << 25) | (_j << 23) | _k;
if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + task[i + 1].a) {
dp[_i & 1][_j][_k] = dp[i & 1][j][k] + task[i + 1].a;
if (state_set.find(state) == state_set.end()) {
que.push(DpState(_i, _j, _k));
state_set.insert(state);
}
}
}
if (task[i + 1].b <= k) {
int _i = i + 1, _j = j, _k = k - task[i + 1].b;
int state = (_i << 25) | (_j << 23) | _k;
if (dp[_i & 1][_j][_k] > dp[i & 1][j][k]) {
dp[_i & 1][_j][_k] = dp[i & 1][j][k];
if (state_set.find(state) == state_set.end()) {
que.push(DpState(_i, _j, _k));
state_set.insert(state);
}
}
} else {
int _i = i + 1, _j = j ^ 1, _k = task[i + 1].b - k;
int state = (_i << 25) | (_j << 23) | _k;
if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + _k) {
dp[_i & 1][_j][_k] = dp[i & 1][j][k] + _k;
if (state_set.find(state) == state_set.end()) {
que.push(DpState(_i, _j, _k));
state_set.insert(state);
}
}
}
} else {
// use b
{
int _i = i + 1, _j = j, _k = k + task[i + 1].b;
int state = (_i << 25) | (_j << 23) | _k;
if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + task[i + 1].b) {
dp[_i & 1][_j][_k] = dp[i & 1][j][k] + task[i + 1].b;
if (state_set.find(state) == state_set.end()) {
que.push(DpState(_i, _j, _k));
state_set.insert(state);
}
}
}
if (task[i + 1].a <= k) {
int _i = i + 1, _j = j, _k = k - task[i + 1].a;
int state = (_i << 25) | (_j << 23) | _k;
if (dp[_i & 1][_j][_k] > dp[i & 1][j][k]) {
dp[_i & 1][_j][_k] = dp[i & 1][j][k];
if (state_set.find(state) == state_set.end()) {
que.push(DpState(_i, _j, _k));
state_set.insert(state);
}
}
} else {
int _i = i + 1, _j = j ^ 1, _k = task[i + 1].a - k;
int state = (_i << 25) | (_j << 23) | _k;
if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + _k) {
dp[_i & 1][_j][_k] = dp[i & 1][j][k] + _k;
if (state_set.find(state) == state_set.end()) {
que.push(DpState(_i, _j, _k));
state_set.insert(state);
}
}
}
}
dp[i & 1][j][k] = MAX_VAL;
}
cout << ans << endl;
}
return 0;
}