#include <bits/stdc++.h>
using namespace std;
map<long long, int> cont;
int n;
int ans;
int main() {
  while (~scanf("%d", &n)) {
    int a;
    long long num = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a);
      num += a;
      ans = max(ans, ++cont[num]);
    }
    printf("%d\n", n - ans);
  }
  cont.clear();
  return 0;
}
