#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
long long f[N];
int pre_pos[N];
int num[N], len[N];
map<long long, int> pre, suf;
int ans;
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &f[i]);
  }
  long long s;
  s = 0LL;
  for (int i = n; i >= 1; i--) {
    s += f[i];
    if (suf.find(s) == suf.end()) suf[s] = i;
  }
  s = 0LL;
  pre[0LL] = 0;
  for (int i = 1; i <= n; i++) {
    s += f[i];
    if (pre.find(s) == pre.end())
      pre_pos[i] = suf[-s];
    else
      pre_pos[i] = pre[s] + 1;
    pre[s] = i;
  }
}
void work() {
  ans = n - 1;
  for (int i = 1; i <= n; i++) {
    if (pre_pos[i] > i)
      len[i] = i + n - pre_pos[i] + 1, num[i] = 1;
    else
      len[i] = len[pre_pos[i] - 1] + i - pre_pos[i] + 1,
      num[i] = num[pre_pos[i] - 1] + 1;
    if (len[i] == n) ans = min(ans, n - num[i]);
  }
  cout << ans << endl;
}
int main() {
  init();
  work();
  return 0;
}
