#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, sum, ans = 360;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int s = 0; s < n; s++) {
    sum = 0;
    for (int i = s, c = 0; c < n; i++, c++) {
      i %= n;
      sum += a[i];
      y = 360 - sum;
      ans = min(ans, abs(sum - y));
    }
  }
  cout << ans << endl;
  return 0;
}
