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