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