#include using namespace std; const int MAXN = 32; int N; long long A[MAXN], B[MAXN]; int main() { cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i] >> B[i]; } if (N == 1) { cout << min(A[0], B[0]) << endl; exit(0); } int hn = N / 2; set bag; for (int s = 0; s < 1 << hn; ++s) { long long diff = 0; for (int i = 0; i < hn; ++i) { if (s >> i & 1) { diff += A[i]; } else { diff -= B[i]; } } bag.emplace(diff); } long long ans = 1LL << 62; for (int s = 0; s < 1 << N - hn; ++s) { long long diff = 0; for (int i = 0; i < N - hn; ++i) { if (s >> i & 1) { diff += A[hn + i]; } else { diff -= B[hn + i]; } } auto it = bag.lower_bound(-diff); if (it != bag.begin()) --it; for (int i = 0; i < 3; ++i) { if (it == bag.end()) break; ans = min(ans, abs(diff + *it)); ++it; } } cout << ans << endl; return 0; }