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