#include <bits/stdc++.h>
using namespace std;
long long int arr[1000005], t = 0;
int main() {
  int n, cnt;
  cin >> n;
  map<long long int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cnt = 1;
  long long int t = arr[0];
  m[t]++;
  for (int i = 1; i < n; i++) {
    t = t + arr[i];
    m[t]++;
    cnt = max(cnt, m[t]);
  }
  cout << n - cnt << endl;
  return 0;
}
