#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  int diff = 0;
  int diff1 = 360;
  int min;
  int d1, d2;
  d1 = d2 = 1000;
  int num1, num2;
  if (n == 1)
    cout << "360";
  else {
    for (int i = 0; i < n; i++) {
      diff = 0;
      diff1 = 360;
      for (int j = i; j < n - 1; j++) {
        diff += arr[j];
        diff1 -= arr[j];
        d1 = std::min(d1, abs(diff - diff1));
      }
    }
    cout << d1 << endl;
  }
  return 0;
}
