#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using vpi = vector<pair<long long, long long>>;
using vvi = vector<vi>;
using tp = tuple<long long, long long, long long>;
using pi = pair<long long, long long>;
void __READ__() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  };
  return _in;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
const long long nax = 1e5 + 7;
const long long mod = 1e9 + 7;
const long long inf = numeric_limits<long long>::max() - (long long)9e6;
void test() {
  long long n;
  cin >> n;
  vi v(n);
  cin >> v;
  long long ans = inf;
  map<long long, long long> m;
  long long rsum = 0;
  for (long long x : v) {
    rsum += x;
    m[rsum]++;
    ans = min(ans, n - m[rsum]);
  }
  cout << ans;
}
signed main() {
  __READ__();
  long long T = 1;
  for (long long tt = 1; tt <= T; tt++) {
    test();
    cout << "\n";
  }
  return 0;
}
