#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> b(n);
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    s += a[i];
    b[i] = s;
  }
  sort(b.begin(), b.end());
  long long mst = 0, st = 0, prev = 10000000000000000;
  for (long long i : b) {
    if (prev == i)
      st++;
    else {
      mst = max(mst, st);
      st = 1;
      prev = i;
    }
  }
  mst = max(mst, st);
  cout << n - mst;
}
