#include <bits/stdc++.h>
using namespace std;
int const N = 441;
int const INF = 1e9 + 41;
int a[N];
int n;
int ans;
int sum(int l, int r) {
  int res = 0;
  for (int i = l; i < r + 1; ++i) res += a[i];
  return res;
}
void solve() {
  ans = INF;
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j) {
      int v0 = sum(i, j);
      int v1 = sum(0, i - 1);
      int v2 = sum(j + 1, n);
      ans = min(ans, abs(v0 - v1 - v2));
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  solve();
  printf("%d\n", ans);
  return 0;
}
