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