#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp;
map<long long int, long long int>::iterator it;
int main() {
  long long int n, sum = 0, tp;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &tp);
    sum += tp;
    mp[sum]++;
  }
  long long int k = 0;
  for (it = mp.begin(); it != mp.end(); it++) {
    k = max(k, it->second);
  }
  cout << n - k << endl;
}
