#include <bits/stdc++.h>
using namespace std;
int compare(const void *a, const void *b) {
  if (*(long long *)a - *(long long *)b > 0) return 1;
  if (*(long long *)a - *(long long *)b < 0) return -1;
  if (*(long long *)a - *(long long *)b == 0) return 0;
}
int main() {
  long n;
  cin >> n;
  long *a = new long[n];
  long long *sum = new long long[n];
  for (long i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      sum[0] = a[0];
    else
      sum[i] = sum[i - 1] + a[i];
  }
  qsort(sum, n, sizeof(long long), compare);
  long max = 1;
  long tmp = 1;
  long long sum_tmp = sum[0];
  for (long i = 1; i < n; i++) {
    if (sum_tmp == sum[i]) {
      tmp++;
    } else {
      if (max < tmp) max = tmp;
      tmp = 1;
      sum_tmp = sum[i];
    }
  }
  if (max < tmp) max = tmp;
  cout << n - max;
  delete[] sum;
  delete[] a;
  return 0;
}
