#include <bits/stdc++.h>
using namespace std;
long long a[200012];
map<long long, int> m;
int main() {
  int n;
  cin >> n;
  bool ok = 0;
  int in = -1;
  long long pref = 0;
  ;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref += a[i];
    m[pref] += 1;
    cnt = max(cnt, m[pref]);
  }
  cout << n - cnt << "\n";
  return 0;
}
