#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int inf = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long power(long long a, long long b, long long m = 1000000007) {
  long long answer = 1;
  while (b) {
    if (b & 1) answer = (answer * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return answer;
}
using namespace std;
int main() {
  int n;
  cin >> n;
  long long A[n];
  for (int i = 0; i < n; i += 1) cin >> A[i];
  long long second = 0;
  int mx = 0;
  map<long long, int> mp;
  for (int i = 0; i < n; i += 1) {
    second += A[i];
    mp[second]++;
    mx = max(mx, mp[second]);
  }
  cout << n - mx;
  return 0;
}
