#include <bits/stdc++.h>
using namespace std;
const int limite = 1000000;
int n;
long long int a[limite];
long long int suma[limite];
map<long long int, int> cuantos;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  for (int i = 1; i <= 2 * n; i++) suma[i] = suma[i - 1] + a[i];
  for (int i = 1; i <= n; i++) cuantos[suma[i]]++;
  int sol = n;
  for (int i = 1; i <= n; i++) {
    sol = min(sol, n - cuantos[suma[i - 1]]);
    cuantos[suma[i]]--;
    cuantos[suma[i + n]]++;
  }
  cout << sol << endl;
}
