#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N * 2];
long long d[N * 2];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = n + 1; i <= 2 * n; ++i) {
    a[i] = a[i - n];
  }
  for (int i = 1; i <= 2 * n; ++i) {
    d[i] = d[i - 1] + a[i];
  }
  int j = 1;
  map<long long, int> mp;
  mp[d[0]]++;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    for (; j < i + n; ++j) {
      mp[d[j]]++;
    }
    mp[d[i - 1]]--;
    mx = max(mx, mp[d[i - 1]]);
  }
  printf("%d\n", n - mx);
  return 0;
}
