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