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