#include <bits/stdc++.h>
using namespace std;
inline int iseven(int x) { return x & 1 ? 0 : 1; }
inline bool is_double(double x) {
  double y = x - (int)x;
  return (y == x ? true : false);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long prefix[n], sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    prefix[i] = sum;
  }
  map<long long, int> mp;
  long max = 0;
  for (int i = 0; i < n; i++) {
    long long x = prefix[i];
    mp[x]++;
    if (mp[x] > max) max = mp[x];
  }
  cout << n - max;
}
