#include <bits/stdc++.h>
using namespace std;
int n, in, res;
long long sum = 0;
map<long long, int> m;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  res = n - 1;
  for (int i = 0; i < n; i++) {
    cin >> in;
    sum += in;
    m[sum]++;
    res = min(res, n - m[sum]);
  }
  cout << res << endl;
  return 0;
}
