#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n;
long long v[((int)2e5 + 5)];
long long pre[((int)2e5 + 5)];
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    if (i)
      pre[i] = pre[i - 1] + v[i];
    else
      pre[i] = v[i];
  }
  for (int i = 0; i < n; ++i) mp[pre[i]]++;
  long long k = 0;
  for (auto x : mp) k = max(k, x.second);
  cout << n - k << "\n";
}
