#include <iostream>
using namespace std;

#define INFINITY 999999
#define MAX_PEOPLE 10
#define MAX_VERTICES 2048

int no_people;
int mytime[MAX_PEOPLE+1];
int power[MAX_PEOPLE+1];
int graph[MAX_VERTICES][MAX_VERTICES];  //cost to go from one config to another

void build_graph(){
  for( int i=0; i<power[no_people+1]; i++ ){
    for( int j=0; j<power[no_people+1]; j++ ){
      graph[i][j] = INFINITY;
    }
  }
  for( int start=0; start<power[no_people+1]; start++ ){
    if( !(start & 0x0001) ){
      //move to B
      for( int a=1; a<=no_people; a++ ){
        if( !(start & power[a]) ){
          int end = start | power[a] | 0x0001;
          graph[start][end] = graph[end][start] = mytime[a];
          for( int b=a+1; b<=no_people; b++ ){
            if( !(start & power[b]) ){
              end = start | power[a] | power[b] | 0x0001;
              graph[start][end] = graph[end][start] = (mytime[a]>mytime[b])?mytime[a]:mytime[b];
            }
          }
        }
      }
    }
  }
}

int dijkstra(){
  int shortest[MAX_VERTICES];
  bool visited[MAX_VERTICES];
  
  for( int i=0; i<power[no_people+1]; i++ ){
    shortest[i] = INFINITY;
    visited[i] = false;
  }
  shortest[0] = 0;
  int current = 0;
  while( current!=power[no_people+1]-1 ){
    for( int i=0; i<power[no_people+1]; i++ ){
      if( shortest[current] + graph[current][i] < shortest[i] ){
        shortest[i] = shortest[current] + graph[current][i];
      }
    }
    visited[current] = true;
    
    int next = -1;
    int min = INFINITY;
    for( int i=0; i<power[no_people+1]; i++ ){
      if( !visited[i] && shortest[i]<min ){
        next = i;
        min = shortest[i];
      }
    }
    current = next;
  }
  return shortest[ power[no_people+1]-1 ];
}

int main(){
  int p = 1;
  power[0] = p;
  for( int i=1; i<=MAX_PEOPLE+1; i++ ){
    p *= 2;
    power[i] = p;
  }
  while( cin >> no_people ){
    if( no_people == 0 ){
      break;
    }
    for( int n=1; n<=no_people; n++ ){
      cin >> mytime[n];
    }
    build_graph();
    cout << dijkstra() << endl;
  }
  return 0;
}


