#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int MAXABSA = 1e9 + 9;
int n;
int a[MAXN];
void solve() {
  map<long long, int> mp;
  long long sum = 0;
  int maxv = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    ++mp[sum];
    maxv = max(maxv, mp[sum]);
  }
  printf("%d\n", n - maxv);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  solve();
  return 0;
}
