#include <bits/stdc++.h>
using namespace std;
int n, x[2 * 100005], cnt, res;
long long y[2 * 100005];
map<long long, int> d;
int main() {
  scanf("%d", &n);
  if (n == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]), x[n + i] = x[i];
    y[i] = y[i - 1] + x[i];
    d[y[i]]++;
    if (y[i] != 0) cnt++;
  }
  res = cnt;
  long long s = 0;
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    s += x[i];
    if (res > n - d[s]) res = n - d[s];
  }
  printf("%d", res);
}
