#include <bits/stdc++.h>
using namespace std;
map<long long, int> cnt;
int MAIN() {
  int maxV = 0;
  int n;
  cin >> n;
  long long s = 0;
  for (int i = 0; i < n; i++) {
    long long v;
    cin >> v;
    s += v;
    cnt[s]++;
    maxV = max(maxV, cnt[s]);
  }
  cout << n - maxV << endl;
  return 0;
}
int main() {
  int start = clock();
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  int ret = MAIN();
  return ret;
}
