#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[100005];
long long preA[100005];
int main() {
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  preA[0] = 0;
  for (long long i = 1; i < n; ++i) {
    preA[i] = preA[i - 1] + a[i];
  }
  set<long long> nos;
  map<long long, long long> freq;
  for (long long i = 0; i < n; ++i) {
    if (nos.find(preA[i]) != nos.end()) {
      freq[preA[i]]++;
    } else {
      nos.insert(preA[i]);
      freq[preA[i]] = 1;
    }
  }
  long long maxFreq = -1;
  for (set<long long>::iterator it = nos.begin(); it != nos.end(); ++it) {
    if (maxFreq < freq[*it]) {
      maxFreq = freq[*it];
    }
  }
  cout << n - maxFreq;
}
