#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int IT_MAX = 1 << 17;
const long long MOD = 1000000007;
const int INF = 1034567890;
const long long LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-8;
map<long long, int> Mx;
int main() {
  int N, i, t = 0;
  long long s = 0;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) {
    scanf("%d", &t);
    s += t;
    Mx[s]++;
  }
  int mx = 0;
  for (auto it : Mx) mx = max(mx, it.second);
  return !printf("%d\n", N - mx);
}
