#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7, EPS = 1e-6;
const int N = 1e5 + 5;
int n, x;
long long s, m;
map<long long, long long> c;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &x), s += x, m = max(m, ++c[s]);
  printf("%I64d\n", n - m);
  return 0;
}
