#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> f;
long long n, x, now, ans;
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    now += x;
    ans = max(ans, ++f[now]);
  }
  cout << n - ans << endl;
}
