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