#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int main() {
  int n;
  cin >> n;
  long long ans = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    mp[sum]++;
    ans = max(ans, mp[sum]);
  }
  cout << n - ans << endl;
}
