#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long, long long> cnt;
  long long n, large = 0;
  long long now = 0;
  scanf("%I64d", &n);
  for (int i = 0; i < n; i++) {
    long long a;
    scanf("%I64d", &a);
    now += a;
    cnt[now]++;
  }
  for (map<long long, long long>::iterator it = cnt.begin(); it != cnt.end();
       it++) {
    large = max(large, it->second);
  }
  printf("%I64d\n", n - large);
  return 0;
}
