#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, sum = 0, b, c, min = INT_MAX;
  cin >> n;
  int a[n], suf[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    if (i)
      suf[i] = suf[i - 1] + a[i];
    else
      suf[i] = a[i];
  }
  if (n == 1)
    cout << a[0];
  else if (n == 2)
    cout << abs(a[0] - a[1]);
  else {
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        b = suf[j] - suf[i];
        c = abs(b - sum);
        if (abs(b - c) < min) min = abs(b - c);
      }
    }
    cout << min;
  }
  return 0;
}
