#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int sum[1000] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    if (i != 0)
      sum[i] = sum[i - 1] + arr[i];
    else
      sum[i] = arr[i];
  }
  int mi = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int sum1 = sum[j] - sum[i] + arr[i];
      int sum2 = sum[n - 1] - sum1;
      mi = min(mi, abs(sum1 - sum2));
    }
  }
  cout << mi << "\n";
  return 0;
}
