import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto tokens = my_readln.split;
	auto N = tokens[0].to!uint;
	auto a = new ulong[](N);

	foreach (i, token; my_readln.split)
		a[i] = token.to!ulong;

	auto used = new uint[](N);
	ulong ans;
	
	foreach (i; 0..N-1)
	{
		ulong[2] bestPos;
		ulong best = ulong.max, last, lastPos;
		foreach (j; 0..N)
		{
			if (used[j] == 1) continue;

			if (last != 0 && last + a[j] < best)
			{
				best    = last + a[j];
				bestPos = [lastPos, j];
			}
			last    = a[j];
			lastPos = j;
		}
		a[bestPos[0]]    = best;
		used[bestPos[1]] = 1;
		ans += best;
		//stderr.writeln(bestPos, " ", best);
	}
	
	writeln(ans);
	stdout.flush();
}