#include <bits/stdc++.h>
using namespace std;
int vis[100005];
map<long long int, vector<int> > m;
vector<long long int> sumu;
int n;
int find(int i, int depth) {
  ;
  if (vis[i] != -2) return 0;
  auto it = upper_bound(m[sumu[i]].begin(), m[sumu[i]].end(), i);
  if (it == m[sumu[i]].end()) return vis[i] = depth;
  return vis[i] = find(*it, depth + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i;
  cin >> n;
  for (int i = 0; i < 100005; i++) vis[i] = -2;
  vector<int> inp(n);
  sumu.resize(n + 1);
  sumu[0] = 0;
  for (int i = 0; i < n; i++) cin >> inp[i];
  m[sumu[0]].push_back(0);
  for (int i = 1; i <= n; i++) {
    sumu[i] = sumu[i - 1] + inp[i - 1];
    m[sumu[i]].push_back(i);
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(find(i, 0) + (i == 0 ? 0 : 1), ans);
  }
  cout << n - ans << '\n';
  return 0;
}
