#include <stdio.h>

#define MIN(A,B) \
  ( (A) < (B) ? (A) : (B) )
#define ABS(X) \
  ( (X) < 0 ? -(X) : (X) )

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    int d[ 20 ];
    int sum = 0, res;
    int n;

    scanf ( "%d", &n );
    if ( !n ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", d + i );
      sum     += d[ i ];
      d[ i ]  *= 2;
    }

    res = sum;
    for ( j = 0; j < ( 1 << n ); ++j )
    {
      int t = sum;

      for ( i = 0; i < n; ++i )
      {
        if ( j & ( 1 << i ) )
        {
          t -= d[ i ];
        }
      }

      res = MIN( res, ABS( t ) );
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}