#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
int n;
int main() {
  scanf("%d", &n);
  int t;
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    s += t;
    mp[s]++;
  }
  int ans = 0;
  map<long long, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    ans = max(ans, it->second);
  }
  printf("%d\n", n - ans);
  return 0;
}
