#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5, oo = 1e9;
map<long long, long long> M;
long long a[maxn], p[maxn];
long long ans, i, n;
int main() {
  scanf("%I64d", &n);
  ans = oo;
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    p[i] = p[i - 1] + a[i];
    M[p[i]]++;
    ans = min(ans, n - M[p[i]]);
  }
  printf("%I64d", ans);
  return 0;
}
