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