#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1e+9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed;
  cout << setprecision(10);
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  ll sum = 0;
  map<ll, int> mp;
  for (int i = 1; i <= n; i++) {
    sum += arr[i];
    mp[sum]++;
  }
  int h = 0;
  for (auto p : mp) h = max(h, p.second);
  cout << n - h;
}
