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