#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n, 0);
  int cs = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cs += a[i];
  }
  int d = 0, minn = 1000000;
  for (int i = 0; i < n; i++) {
    d = a[i];
    minn = min(minn, abs(cs - 2 * d));
    for (int j = (i + 1) % n; j != i; j = (j + 1) % n) {
      d += a[j];
      minn = min(minn, abs(cs - 2 * d));
    }
  }
  cout << minn << endl;
  return 0;
}
