#include<iostream>
#include<bitset>
using namespace std;

int diff( int a, int b )
{
    int c = a - b;
    return c < 0 ? -c : c;
}

int main()
{
    int n;
    bitset<20> b;

    while( cin >> n )
    {
        if( !n )
            break;

        int* a = new int[n];

        int sum = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> a[i];
            sum += a[i];
        }

        int limit = 1;
        for( int i = 0; i < n; i++ )
            limit *= 2;

        int min = 1000000000;
        for( int i = 1; i < limit; i++ )
        {
            b = i;
            int s = 0;
            for( int i = 0; i < n; i++ )
                if( b[i] )
                    s += a[i];
            int d = diff( s, sum - s );
            if( min > d )
                min = d;
        }
        
        cout << min << endl;
        delete a;
    }
    return 0;
}
