#include <bits/stdc++.h>
using namespace std;
map<long long, int> m;
int n, res = 1e9;
long long sum, x;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    sum += x;
    m[sum]++;
    res = min(res, n - m[sum]);
  }
  cout << res;
}
