#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < (int)n; i++) cin >> a[i];
  vector<long long> b(n);
  b[0] = a[0];
  for (int i = 0; i < (int)n - 1; i++) b[i + 1] = b[i] + a[i + 1];
  sort(b.begin(), b.end());
  int m = 0;
  int k = 0;
  for (int i = 0; i < (int)n - 1; i++) {
    if (b[i + 1] == b[i])
      k++;
    else {
      k = 0;
    }
    if (m < k) m = k;
  }
  cout << n - 1 - m << endl;
  return 0;
}
