#include <bits/stdc++.h>
using namespace std;
long long arr[500005];
map<long long, int> mm;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i]);
  for (int i = 1; i <= n - 1; i++) arr[i] += arr[i - 1];
  for (int i = 0; i < n; i++) mm[arr[i]]++;
  int mx = -1;
  map<long long, int>::iterator it;
  for (it = mm.begin(); it != mm.end(); it++) {
    mx = max(mx, it->second);
  }
  printf("%d\n", n - mx);
  return 0;
}
