#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 4e18;
const int N = 300000;
int n, a[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n; i < 2 * n; i++) a[i + n] = a[i];
  int s = 0;
  int ans = 361;
  for (int i = 0; i < n; i++) s += a[i];
  for (int i = 0; i < n; i++) {
    int s1 = 0;
    for (int j = i; j < i + n; j++) {
      s1 += a[j];
      int s2 = s - s1;
      if (abs(s1 - s2) < ans) {
        ans = abs(s1 - s2);
      }
    }
  }
  cout << ans;
  return 0;
}
