#include <bits/stdc++.h>
using namespace std;
const int iinf = 0x7fffffff;
const long long linf = ~(1LL << 63);
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long qpow(long long a, long long n, long long mod) {
  a %= mod;
  n %= mod;
  long long ans = 1LL;
  while (n) {
    if (n & 1) ans = (ans * a % mod);
    a = (a * a % mod);
    n >>= 1;
  }
  return ans;
}
inline long long rev(long long a, long long p) { return qpow(a, p - 2, p); }
const int maxn = 100002;
int inp[maxn];
map<long long, int> times;
int main() {
  int n;
  cin >> n;
  long long mi = -1;
  int start = 0;
  long long prefix = 0;
  int ans = n - 1;
  for (int i = 0; i < n; i++) {
    cin >> inp[i];
    prefix += inp[i];
    times[prefix] += 1;
    ans = min(ans, n - times[prefix]);
  }
  cout << ans << endl;
  return 0;
}
