#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  std::map<long long, long long> mp;
  long long s = 0;
  long long ans = INT_MAX;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    s += x;
    mp[s]++;
    ans = min(ans, n - mp[s]);
  }
  cout << ans << "\n";
  return 0;
}
