#include <bits/stdc++.h>
using namespace std;
map<long long int, int> mp;
long long int sum = 0;
int main() {
  int n, temp, ans = 0;
  scanf("%d", &n);
  for (int ii = 0; ii < n; ii++) {
    scanf("%d", &temp);
    sum += temp;
    mp[sum]++;
    ans = max(ans, mp[sum]);
  }
  printf("%d\n", n - ans);
}
