#include <bits/stdc++.h>
using namespace std;
map<long long, int> cnt;
int n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  long long sum = 0;
  int ans = 0, num;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    sum += num;
    ++cnt[sum];
    ans = max(ans, cnt[sum]);
  }
  cout << n - ans << endl;
  return 0;
}
