#include <bits/stdc++.h>
using namespace std;
int dadsadasda;
const int INF = 0x3f3f3f3f;
const long long LLINF = 1e18;
const int MAXN = 1e5;
int main() {
  int n;
  dadsadasda = scanf("%d", &n);
  long long sm = 0;
  long long ans = n - 1;
  map<long long, long long> cnt;
  for (int i = 0; i < n; i++) {
    long long aux;
    dadsadasda = scanf("%lld", &aux);
    sm += aux;
    cnt[sm]++;
    ans = min(ans, 1ll * n - cnt[sm]);
  }
  printf("%lld\n", ans);
  return 0;
}
