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