#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 1e+9;

int n, a[21], ans;

void dfs(int diff, int k)
{
    if (k == n)
    {
        ans = min(ans, abs(diff));
    }
    else
    {
        dfs(diff + a[k], k + 1);
        dfs(diff - a[k], k + 1);
    }
}

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

        ans = INF;

        dfs(0, 0);

        cout << ans << endl;
    }
}