#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long, int> m;
  int n, t = 0;
  long long a, s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    s += a;
    t = max(t, ++m[s]);
  }
  cout << n - t;
  return 0;
}
