#include <bits/stdc++.h>
using namespace std;
constexpr int64_t kPhi = 5700357409661599242LL;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) {
    cin >> x;
  }
  vector<int64_t> suffix_sum(n + 1);
  for (int i = n - 1; i >= 0; i -= 1) {
    suffix_sum[i] = a[i] + suffix_sum[i + 1];
  }
  unordered_map<int64_t, int> sum_blocks;
  sum_blocks.reserve(n);
  sum_blocks.max_load_factor(0.25);
  int64_t sum = 0;
  int ans = n;
  for (int i = 0; i < n; i += 1) {
    sum += a[i];
    auto&& iter = sum_blocks.find(-suffix_sum[i + 1] ^ kPhi);
    if (iter != sum_blocks.end()) {
      ans = min(ans, n - iter->second);
    }
    sum_blocks[sum ^ kPhi]++;
  }
  cout << ans - 1 << endl;
}
