#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  cin >> v[0];
  map<long long int, long long int> m;
  m[v[0]]++;
  for (long long int i = 1; i < n; i++) {
    cin >> v[i];
    v[i] = v[i - 1] + v[i];
    m[v[i]]++;
  }
  long long int ma = m[v[0]];
  for (map<long long int, long long int>::iterator it = m.begin();
       it != m.end(); it++) {
    if (it->second > ma) ma = it->second;
  }
  cout << n - ma << endl;
}
