#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  map<long long, int> mapka;
  long long cur = 0;
  mapka[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (i == 0) continue;
    cur += a[i];
    mapka[cur]++;
  }
  int mx = 0;
  for (auto it = mapka.begin(); it != mapka.end(); ++it)
    mx = max(mx, it->second);
  cout << n - mx;
  return 0;
}
