#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
int main(int argc, char** argv) {
  int n;
  cin >> n;
  long long t;
  int x = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    mp[t += x]++;
  }
  int s = 0;
  for (std::map<long long, int>::iterator it = mp.begin(); it != mp.end(); ++it)
    s = max(s, it->second);
  cout << n - s;
  return 0;
}
