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