#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
typedef long long ll ;
set < ll > st ;
void make_sums (vector < ll > &a , ll index , ll sum , ll maxi , ll total ) {
if (index == maxi ) {
st.insert(abs(total - 2 * sum) ) ;
return ;
}
make_sums (a , index+1 , sum+a[index] , maxi , total );
make_sums (a , index+1 , sum , maxi, total );
}
void solve() {
ll n ;
cin >> n ;
vector<ll> a(n) ;
ll total = 0 ;
for (ll i = 0 ; i < n ; i++) {
cin >> a[i] ;
total += a[i] ;
}
make_sums (a, 0, 0, n , total) ;
cout <<*st.begin()<< endl ;
}
int main() {
ll t ;
t=1;
///cin >> t ;
while (t-- ) {
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lIHBiIHB1c2hfYmFjawp0eXBlZGVmIGxvbmcgbG9uZyBsbCA7CiBzZXQgPCBsbCA+IHN0IDsKdm9pZCBtYWtlX3N1bXMgKHZlY3RvciA8IGxsID4gJmEgICwgbGwgaW5kZXggICwgbGwgc3VtICwgbGwgbWF4aSAgLCBsbCB0b3RhbCAgKSB7CiAgICBpZiAoaW5kZXggPT0gbWF4aSApIHsKICAgICAgICBzdC5pbnNlcnQoYWJzKHRvdGFsIC0gMiAqIHN1bSkgICkgOwogICAgICAgIHJldHVybiA7CiAgICB9CiAgICBtYWtlX3N1bXMgKGEgICwgaW5kZXgrMSAsIHN1bSthW2luZGV4XSAsIG1heGkgICwgdG90YWwgICk7CiAgICBtYWtlX3N1bXMgKGEgICwgaW5kZXgrMSAsIHN1bSAsIG1heGksIHRvdGFsICApOwoKfQoKCnZvaWQgc29sdmUoKSB7CiAgICBsbCBuIDsKCiAgICBjaW4gPj4gbiAgOwogICAgdmVjdG9yPGxsPiBhKG4pIDsKICAgIGxsIHRvdGFsICA9IDAgOwogICAgZm9yI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