#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
int main() {
  int n;
  long long num, cur, ans = 0;
  while (cin >> n) {
    m.clear();
    cur = 0;
    ans = 0;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      cur += num;
      ans = max(ans, ++m[cur]);
    }
    cout << n - ans << endl;
  }
  return 0;
}
