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