#include <bits/stdc++.h>
using namespace std;
int N, ans, a;
long long sum;
map<long long, int> freq;
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a);
    sum += a;
    ans = max(ans, ++freq[sum]);
  }
  printf("%d\n", N - ans);
  return 0;
}
