#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, ans;
  long long sum = 0, a;
  map<long long, int> m;
  scanf("%d", &n);
  ans = n - 1;
  for (i = 1; i <= n; i++) {
    cin >> a;
    sum += a;
    m[sum]++;
    ans = min(ans, n - m[sum]);
  }
  cout << ans << endl;
  return 0;
}
