#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20;
long long n, a[N], f[N];
map<long long, long long> cnt;
int main() {
  while (cin >> n) {
    f[0] = 0;
    long long mx = 0;
    for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), f[i] = f[i - 1] + a[i];
    for (int i = 1; i <= n; i++) {
      if (f[i] == 0) mx++;
    }
    long long m = 0;
    for (int i = 1; i <= n; i++) {
      cnt[f[i]]++;
      if (cnt[f[i]] > m) m = cnt[f[i]];
    }
    mx = max(mx, m);
    cout << n - mx << endl;
  }
  return 0;
}
