#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[360], t1, t2, t3, ans = 1e9;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  if (n == 1) {
    printf("360\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    t1 = 0;
    for (int j = i; j < n; j += 1) {
      t1 += a[j];
      t2 = 360 - t1;
      ans = min(ans, abs(t1 - t2));
    }
  }
  printf("%d\n", ans);
}
