#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000 + 10;
int mx, n, a, sar = 1;
long long ps[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ps[i + 1] = ps[i] + a;
  }
  sort(ps + 1, ps + n + 1);
  for (int i = 2; i <= n; i++) {
    if (ps[i] != ps[i - 1]) {
      mx = max(mx, i - sar);
      sar = i;
    }
  }
  mx = max(mx, n + 1 - sar);
  cout << n - mx;
  return 0;
}
