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