#include <bits/stdc++.h>
using namespace std;
long long a[100001];
long long p[100001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  p[0] = a[0];
  for (int i = 1; i < n; i++) p[i] = p[i - 1] + a[i];
  map<long long, int> y;
  for (int i = 0; i < n; i++) {
    y[p[i]]++;
  }
  int k = 0;
  for (map<long long, int>::iterator i = y.begin(); i != y.end(); i++) {
    k = max(k, i->second);
  }
  cout << n - k << endl;
  return 0;
}
