#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = int(1e5) + 10;
map<long long int, int> mp;
int main() {
  int n;
  scanf("%d", &n);
  int ans = n;
  long long int s = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    s += x;
    mp[s]++;
    ans = min(ans, n - mp[s]);
  }
  cout << ans << endl;
  return 0;
}
