#include <bits/stdc++.h>
using namespace std;
int n;
map<long long, int> frec;
int main() {
  int n;
  cin >> n;
  frec.clear();
  long long sum = 0;
  int ans = n - 1;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    sum += x;
    frec[sum]++;
    ans = min(ans, n - frec[sum]);
  }
  cout << ans << endl;
}
