#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
long long x, sums;
int main() {
  map<long long, long long> hoge;
  int n;
  cin >> n;
  long long ans = n - 1;
  sums = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sums += x;
    hoge[sums]++;
    ans = min(ans, (long long)n - hoge[sums]);
  }
  cout << ans << endl;
}
