#include using ll = long long; int main() { int N; std::cin >> N; std::vector C(N), D(N); for (int i = 0; i < N; i++) { std::cin >> C[i] >> D[i]; } std::vector dp{0, C[0]}; for (int i = 1; i < N; i++) { dp[0] = std::min(dp[0] + D[i], dp[1]), dp[1] = std::min(dp[0] + C[i], dp[1] + D[i]); } std::cout << dp[1] + std::accumulate(C.begin(), C.end(), 0LL) << std::endl; return 0; }