#include <bits/stdc++.h>
using namespace std;
int n, vet[1010];
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 0; i < n; i++)
    scanf("%d", &vet[i]), vet[i + n] = vet[i], sum += vet[i];
  int ans = sum;
  for (int z = 1; z < n; z++) {
    int x = 0;
    for (int i = 0; i < z; i++) {
      x += vet[i];
    }
    ans = min(ans, abs(2 * x - sum));
    for (int i = z; i < n * 2; i++) {
      x += vet[i];
      x -= vet[i - z];
      ans = min(ans, abs(2 * x - sum));
    }
  }
  printf("%d\n", ans);
}
