#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
inline int read() {
  static char ch;
  bool sgn = false;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') sgn = true;
  int res = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
  return sgn ? -res : res;
}
int b[200000], a[200000], s[200000], tot, n;
void Ins(int x) {
  while (x <= n) {
    s[x]++;
    x += (x & (-x));
  }
}
int Query(int x) {
  int res = 0;
  while (x > 0) {
    res += s[x];
    x -= (x & (-x));
  }
  return res;
}
vector<long long> v;
map<long long, int> sum;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    s += a[i];
    sum[s]++;
    if (sum[s] == 1) v.push_back(s);
  }
  int ans = 0;
  for (int i = v.size() - 1; i >= 0; i--) {
    if (sum[v[i]] > ans) ans = sum[v[i]];
  }
  cout << n - ans;
}
