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