#include <bits/stdc++.h>
int main() {
  int n, min, slice, sum;
  std::cin >> n;
  std::vector<bool> got(361, false);
  std::vector<int> inp(n);
  got[0] = true;
  for (int i = 0; i < n; ++i) {
    std::cin >> inp[i];
  }
  for (int i = 0; i < n; ++i) {
    sum = 0;
    for (int t = i; t < n; ++t) {
      sum += inp[t];
      got[sum] = true;
    }
  }
  min = 360;
  for (int i = 0; i < 361; ++i) {
    if (got[i]) {
      min = std::min(min, std::abs(360 - 2 * i));
    }
  }
  std::cout << min;
  return 0;
}
