/*
AizuOnline A1045
Split Up!
*/
#include <stdio.h>




main()
{
  int i,j;
  long int sumdiff;
  long int minsumdiff;
  long int members[20]={1,2,3,4,80,100,2};
  int  n  = 7;

  
while(EOF != scanf("%d",&n) && n > 0)
    {
      
      i=0;
      for(i=0;i<n;i++)
        scanf(" %d",&(members[i]));
  
      minsumdiff = 1000000;
      for(i=0;i<(1<<n-1);i++)
        {  
          sumdiff=0;
          for(j=0;j<n;j++)
            { 
              sumdiff += ((i & (1<<j))?(-1):1) * members[j];
            }
          sumdiff = (sumdiff<0)?(-sumdiff):(sumdiff);
          
          if(sumdiff < minsumdiff)
            minsumdiff = sumdiff;
        }
  
      printf("%d\n",minsumdiff);
    }
return(0);
}