#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
long long n;
long long a[MaxN + 5];
map<long long, long long> cnt;
int main() {
  scanf("%d", &n);
  long long sum = 0, maxcnt = 0, MAX = -1;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
    cnt[sum]++;
    if (cnt[sum] > maxcnt) maxcnt = cnt[sum];
  }
  printf("%I64d\n", n - maxcnt);
  return 0;
}
