#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn];
map<long long, long long> cnt;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  long long sum = 0, mx = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    mx = max(mx, ++cnt[sum]);
  }
  cout << n - mx << endl;
}
