#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unsigned long long sum_up_to_here = 0;
  map<unsigned long long, int> nsums;
  int ngroups = 1;
  for (int x = 0; x < n; x++) {
    int t;
    cin >> t;
    sum_up_to_here += t;
    nsums[sum_up_to_here]++;
    if (nsums[sum_up_to_here] > ngroups) ngroups = nsums[sum_up_to_here];
  }
  cout << n - ngroups << "\n";
}
