#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 n;
  cin >> n;
  map<i64, i64> mp;
  i64 s = 0, a, ans = n - 1;
  for (i64 i = 0; i < n; ++i) {
    cin >> a;
    s += a;
    mp[s]++;
    ans = min(ans, n - mp[s]);
  }
  cout << ans << endl;
  return 0;
}
