import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long[] B) {
    auto A = new long[](cast(size_t) N);
    A.fill(-1);
    foreach (t; B.enumerate.array.sort!"a[1] < b[1]"()) {
        auto i = t[0];
        if (A[i] == -1)
            A[i] = B[i];
        if (A[i + 1] == -1)
            A[i + 1] = B[i];
    }
    return sum(A);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] B = new long[](cast(size_t) (N-1));
    foreach (i; 0 .. cast(size_t) (N-1)) {
        B[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, B);
    else
        solve(N, B).writeln;
}
