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