#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100000];
vector<long long> v;
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  v.push_back(0);
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sum += a[i];
    v.push_back(sum);
  }
  sort(v.begin(), v.end());
  int cur = 0;
  int mx = 1;
  for (int i = 1; i < v.size(); i++) {
    if (v[i] != v[i - 1]) {
      mx = max(mx, i - cur);
      cur = i;
    }
  }
  mx = max(mx, n - cur);
  cout << n - mx << "\n";
  return 0;
}
