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