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