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