#include <bits/stdc++.h>
using namespace std;
int a[800];
int main() {
  int n, minval, sum, tot;
  cin >> n;
  tot = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    tot += a[i];
  }
  for (int i = 1; i <= n; ++i) {
    a[i + n] = a[i];
  }
  minval = tot;
  for (int i = 1; i <= n; ++i) {
    sum = 0;
    for (int j = i; j <= 2 * n; ++j) {
      if (j - i == n) break;
      sum += a[j];
      minval = min(abs(tot - 2 * sum), minval);
    }
  }
  cout << minval << endl;
  return 0;
}
