#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  vector<long long> pref(n, 0);
  for (int i = 0; i < n; i++) {
    pref[i] = nums[i];
    if (i) pref[i] += pref[i - 1];
  }
  map<long long, int> cnt;
  for (long long x : pref) {
    cnt[x] += 1;
  }
  int best = 0;
  for (auto it : cnt) {
    if (it.second > best) best = it.second;
  }
  cout << n - best << '\n';
  return 0;
}
