#include <bits/stdc++.h>
using namespace std;
int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); }
map<long long, long long> mp;
int main() {
  long long n, m, s, ans = n - 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    s += m;
    ans = min(ans, n - (++mp[s]));
  }
  cout << ans << endl;
  return 0;
}
