#include <limits>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int n; cin >> n && n;) {
		vector<int> powers(n);
		for(auto &e : powers) cin >> e;

		const int total = accumulate(powers.begin(), powers.end(), 0);
		unordered_set<int> s{0};
		for(const auto &p : powers) {
			unordered_set<int> tmp(s);
			for(const auto &sum : tmp) {
				s.insert(sum + p);
			}
		}

		int ans = numeric_limits<int>::max();
		for(const auto &sum : s) {
			ans = min(ans, abs(sum - (total - sum)));
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}