#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e5 + 2;
const long long INF = (long long)1e18 + 1;
const double EPS = 1e-9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<long long> prefix_sum(n);
  for (int i = 0; i < n; ++i) {
    long long cur;
    cin >> cur;
    prefix_sum[i] = cur;
    if (i) prefix_sum[i] += prefix_sum[i - 1];
  }
  sort(prefix_sum.begin(), prefix_sum.end());
  int mf = 1, cf = 1;
  for (int i = 1; i < n; ++i) {
    if (prefix_sum[i] == prefix_sum[i - 1]) {
      ++cf;
    } else {
      if (mf < cf) mf = cf;
      cf = 1;
    }
  }
  if (mf < cf) mf = cf;
  cout << n - mf;
  return 0;
}
