#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, s, x;
  map<long long, long long> mp;
  map<long long, long long>::iterator it;
  cin >> n;
  s = 0;
  for (i = 0; i < n; i++) {
    cin >> x;
    s += x;
    mp[s]++;
  }
  i = -1;
  for (it = mp.begin(); it != mp.end(); it++) {
    i = max(i, it->second);
  }
  cout << n - i << "\n";
}
