#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; constexpr ll INF = (1LL << 55); int main(){ int n; cin >> n; vector a(n), b(n); rep(i,n) cin >> a[i] >> b[i]; vector> dp(n+1, vector(2, INF)); dp[0][0] = 0; dp[0][1] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (j ? b[i] : a[i])); dp[i+1][j] = min(dp[i+1][j], abs(dp[i][(j+1)%2] - (j ? b[i] : a[i]))); } } cout << min(dp[n][0], dp[n][1]) << endl; return 0; }