#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int n;
long long a[N], s[N];
map<long long, int> M;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    a[i + n] = a[i];
  }
  M[0] = 0;
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + a[i];
    M[s[i]]++;
  }
  int res = M[0];
  for (int i = n + 1; i <= 2 * n; i++) {
    s[i] = s[i - 1] + a[i];
    M[s[i - n]]--;
    M[s[i]]++;
    res = max(res, M[s[i - n]]);
  }
  printf("%d\n", n - res);
}
