#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 2e6 + 15;
int main() {
  int n;
  cin >> n;
  long long pref[n + 1];
  pref[0] = 0;
  map<long long, int> f;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> pref[i];
    pref[i] += pref[i - 1];
    f[pref[i]]++;
    mx = max(mx, f[pref[i]]);
  }
  cout << n - mx << "\n";
  return 0;
}
