// yukicoder 860 買い物 // 2019.9.22 bal4u #include typedef long long ll; int getchar_unlocked(void); #define gc() getchar_unlocked() int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } inline static ll MIN(ll a, ll b) { return a <= b? a: b; } int main() { int N, C, D; ll s, t; N = in(); C = in(), D = in(); t = C, s = t << 1; while (--N) { C = in(), D = in(); t = MIN(t+D, s) + C; s = MIN(s+D, t) + C; } printf("%lld\n", s); return 0; }