#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> angles(n);
  for (int i = 0; i < n; i++) {
    int angle;
    cin >> angle;
    angles[i] = angle;
  }
  int difference = 360;
  for (int i = 0; i < n; i++) {
    int current_angle = angles[i];
    for (int j = 1; j < n; j++) {
      int curr_diff = max(current_angle, 360 - current_angle) -
                      min(current_angle, 360 - current_angle);
      difference = min(difference, curr_diff);
      current_angle += angles[(i + j) % n];
    }
    int curr_diff = max(current_angle, 360 - current_angle) -
                    min(current_angle, 360 - current_angle);
    difference = min(difference, curr_diff);
  }
  cout << difference << endl;
  return 0;
}
