#include <bits/stdc++.h>
using namespace std;
long long const N = 1e5 + 20;
long long n, a[N], val[N], ans, mx;
map<long long, long long> mp;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) val[i] = val[i - 1] + a[i - 1];
  ans = n;
  for (long long i = 1; i <= n; i++) {
    mp[val[i]]++;
    mx = max(mx, mp[val[i]]);
  }
  ans -= mx;
  return cout << ans, 0;
}
