#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print_array(T arr[], int size_arr) {
  for (int i = (0); i < (size_arr); i++) {
    cout << arr[i];
    if (i == size_arr - 1)
      cout << endl;
    else
      cout << " ";
  }
}
template <typename T>
void print_vector(vector<T> v) {
  for (int i = (0); i < (v.size()); i++) {
    cout << v[i];
    if (i == v.size() - 1)
      cout << endl;
    else
      cout << " ";
  }
}
template <typename T>
void memset_array(T arr[], T value, int size_arr) {
  for (int i = (0); i < (size_arr); i++) {
    arr[i] = value;
  }
}
bool compare_lexical_string(string a, string b) {
  for (int i = (0); i < (min(a.length(), b.length())); i++) {
    if (a[i] != b[i]) return a[i] < b[i];
  }
  return a.length() < b.length();
}
struct lex_string {
  bool operator()(string a, string b) { return compare_lexical_string(a, b); }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long a[n];
  for (int i = (0); i < (n); i++) cin >> a[i];
  long long c[n];
  c[0] = a[0];
  for (int i = (1); i < (n); i++) {
    c[i] = c[i - 1] + a[i];
  }
  map<long long, int> m;
  for (int i = (0); i < (n); i++) {
    m[c[i]]++;
  }
  int maxx = 0;
  for (auto el : m) {
    if (el.second > maxx) maxx = el.second;
  }
  cout << n - maxx << endl;
  return 0;
}
