#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, num, i;
  cin >> n;
  long long int sum = 0ll;
  int ans = n - 1;
  map<long long int, int> m;
  for (i = 0; i < n; ++i) {
    cin >> num;
    sum += num;
    m[sum]++;
    ans = min(ans, n - m[sum]);
  }
  cout << ans << endl;
  return 0;
}
