#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> s(2 * n);
  s[0] = a[0];
  for (int i = 1; i < (int)s.size(); ++i) s[i] = s[i - 1] + a[i % n];
  map<long long, int> counter;
  long long answer = 1e18;
  for (int l = 0, r = 0; l + n < (int)s.size(); ++l) {
    while (r < l + n) {
      ++counter[s[l + (r - l) % n]];
      ++r;
    }
    long long w = 0;
    if (l > 0) w = s[l - 1];
    long long currentAnswer = n - counter[w];
    answer = min(answer, currentAnswer);
    --counter[s[l]];
  }
  cout << answer << endl;
  return 0;
}
