#include <bits/stdc++.h>
using namespace std;
inline int Mul(int x, int y) { return 1ll * x * y % 1000000007; }
inline int Add(int x, int y) {
  return ((x + y) % 1000000007 + 1000000007) % 1000000007;
}
int n;
long long v[100010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &v[i]), v[i] += v[i - 1];
  sort(v + 1, v + n + 1);
  int Ans = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (i == 1 || v[i] != v[i - 1])
      cnt = 1;
    else
      cnt++;
    Ans = max(Ans, cnt);
  }
  printf("%d\n", n - Ans);
  return 0;
}
