#include <bits/stdc++.h>
using namespace std;
long long int sum;
long long int cnt;
long long int maxs;
long long int a[100001];
map<long long int, long long int> jilu;
long long int maxa(long long int a, long long int b) { return a > b ? a : b; }
int main() {
  int i, n;
  while (scanf("%d", &n) != EOF) {
    cnt = 0;
    sum = 0;
    maxs = 0;
    jilu.clear();
    for (i = 1; i < n + 1; i++) {
      scanf("%lld", &a[i]);
      sum += a[i];
      maxs = maxa(maxs, ++jilu[sum]);
    }
    cnt = n - maxs;
    printf("%lld\n", cnt);
  }
  return 0;
}
