// Arup Guha
// 11/30/2016
// Solution to 2015 NAQ Problem G: Safe Passage

import java.util.*;

public class safepassage {

	public static int n;
	public static int[] nums;

	public static int[] dp;

	public static void main(String[] args) {

		// Read in values.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		nums = new int[n];
		for (int i=0; i<n; i++) nums[i] = stdin.nextInt();

		// Store all results here. (lsb = where is cloak(0=start,1=dest), rest = people at start)
		dp = new int[(1<<(n+1))];
		Arrays.fill(dp, -1);

		// End state, time left is 0.
		dp[1] = 0;

		// This is the mask for the start state.
		System.out.println(solve(dp.length-2));
	}

	public static int solve(int mask) {

		// Memo return!
		if (dp[mask] != -1) return dp[mask];

		// Just to make this easier to read.
		int cloak = (mask & 1);
		int people = mask >> 1;


		if (cloak == 0) {

			int best = 1000000000;

			// Try each pair of people from left.
			for (int i=0; i<n; i++) {
				if ((people & (1<<i)) == 0) continue;
				for (int j=i+1; j<n; j++) {
					if ((people & (1<<j)) == 0) continue;

					// New mask of people on left.
					int left = people - (1<<i) - (1<<j);

					// Send people i and j over to the right, so the cloak is there also.
					int tmp = solve((left<<1)+1) + Math.max(nums[i], nums[j]);
					best = Math.min(best, tmp);
				}
			}

			// Store and return.
			dp[mask] = best;
			return best;
		}

		// Greedy case - fastest person always runs back with the cloak.
		else {
			int right = (1<<n) - 1 - people;
			int fastBit = getFast(right);
			int res = solve((people+(1<<fastBit))<<1) + nums[fastBit];
			dp[mask] = res;
			return res;
		}
	}

	public static int getFast(int mask) {

		// Look for bit that's on that corresponds to fastest person.
		int res = -1;
		for (int i=0; i<n; i++) {
			if ((mask & (1<<i)) == 0) continue;
			if (res == -1 || nums[i] < nums[res])
				res = i;
		}
		return res;
	}
}
