#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, maxoc = -1;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i != 0) a[i] += a[i - 1];
  }
  map<long long, int> occs;
  for (int i = 0; i < n; ++i) {
    occs[a[i]]++;
    maxoc = max(maxoc, occs[a[i]]);
  }
  cout << n - maxoc << endl;
  return 0;
}
