#include <bits/stdc++.h>
using namespace std;
long long mInv[41];
long long fact[41];
long long factInv[41];
map<long long, long long> numCnt;
vector<pair<long, long> > criticalEdges;
vector<long> Graph[29];
long long heights[5];
long long segTree[3];
long nums[5005];
long g[5005];
long long as, cs, rs;
long long am, cm, rm;
long long N, D;
vector<long> primes;
vector<long> badPrimes;
long funcVal[1];
long dfs_num[29], dfs_low[29], visited[29], parent[19], criticalNode[19];
set<string> dictionary;
set<string>::iterator it;
pair<set<string>::iterator, bool> ret;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long getmoduloInv(long long n) {
  if (n == 1) return 1;
  if (mInv[n] > 0) return mInv[n];
  long long m = (-1 * 1000000007) / n;
  m += 1000000007;
  m *= getmoduloInv(1000000007 % n);
  mInv[n] = (m % 1000000007);
  return mInv[n];
}
vector<long> get_primes(unsigned long maxN) {
  char *sieve;
  sieve = new char[maxN / 8 + 1];
  long m = (maxN / 8) + 1;
  for (long long i = 0; i < m; i++) sieve[i] = 255;
  for (unsigned long x = 2; x <= maxN; x++)
    if (sieve[x / 8] & (0x01 << (x % 8))) {
      primes.push_back(x);
      for (unsigned long j = 2 * x; j <= maxN; j += x)
        sieve[j / 8] &= ~(0x01 << (j % 8));
    }
  delete[] sieve;
  return primes;
}
long long getPow(long long b, long long p) {
  if (b < 2 || p == 1) return b;
  if (p == 0) return 1;
  long long val = getPow(b, p / 2);
  val *= val;
  val %= 1000000007;
  if (p % 2 == 1) {
    val *= b;
    val %= 1000000007;
  }
  return val;
}
void buildSegTree(long node, long b, long e) {
  if (b == e)
    segTree[node] = b;
  else {
    long mid = (b + e) / 2;
    buildSegTree(node * 2, b, mid);
    buildSegTree(1 + node * 2, mid + 1, e);
    if (heights[segTree[node * 2]] <= heights[segTree[1 + node * 2]])
      segTree[node] = segTree[node * 2];
    else
      segTree[node] = segTree[1 + node * 2];
  }
}
long long getMin(long node, long segBeg, long segEnd, long qBeg, long qEnd) {
  if (segEnd < qBeg || segBeg > qEnd) return N + 1;
  if (segBeg >= qBeg && segEnd <= qEnd) return segTree[node];
  long mid = (segBeg + segEnd) / 2;
  long fh = getMin(node * 2, segBeg, mid, qBeg, qEnd);
  long sh = getMin(1 + node * 2, mid + 1, segEnd, qBeg, qEnd);
  if (heights[sh] < heights[fh]) return sh;
  return fh;
}
long bff[1100];
long inq[1010];
long source;
long oneEndBig = 0, oneEndSmall = 0, twoendans, zeroendans;
vector<pair<long, pair<long, long> > > allopenANs;
long bigEntry, bigExit, smallEntry, smallExit;
long dfs(long node, long curLen) {
  if (inq[node] == 0) {
    inq[node] = 1;
    dfs(bff[node], curLen + 1);
  } else if (node == source) {
    if (zeroendans < curLen) zeroendans = curLen;
  } else if (bff[bff[node]] == node) {
    curLen -= 2;
    pair<long, pair<long, long> > oA;
    oA.first = curLen;
    oA.second.first = bff[node];
    oA.second.first = node;
    allopenANs.push_back(oA);
  }
  return 0;
}
long dp[10010][5];
long wordLen;
string s1, s2, s3;
long perMutation[20];
long long a[20], b[20], n, k;
pair<long, long> parties[30];
vector<long> shirtsseq;
vector<long> pantseq;
vector<long> jacketseq;
long shirtpantcombo[110];
long shirtjacketcombo[110];
long jacketpantcombo[110];
long S, J, P, K;
double getDist(long long ax, long long ay, long long bx, long long by) {
  double dist = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
  return sqrt(dist);
}
int main(void) {
  long long test_cases = 1, l, seed = 1, maxVal, m;
  long long ax, ay, bx, by, rx, ry, xx, yy, aminpos = 0, aminpos2 = 0,
                                            bminpos = 0, bminpos2 = 0;
  double amin = 1000000000000, amin2 = 1000000000000, bmin = 1000000000000,
         bmin2 = 1000000000000;
  double minDist = 0, cd, ad, bd, rd;
  cout << setprecision(15) << fixed;
  long long tta = 0;
  string s;
  long long charcount[30];
  long long a, b, c, d, x11 = 1, x12, x21, x22;
  long long maxgrp = 1;
  memset(charcount, 0, sizeof(charcount));
  for (long T = 0; T < test_cases; T++) {
    cin >> N;
    long long numb, cumsum = 0;
    for (long i = 0; i < N; i++) {
      scanf("%lld", &numb);
      cumsum += numb;
      long long prevenc = numCnt[cumsum];
      long long totalenc = prevenc + 1;
      numCnt[cumsum] = totalenc;
      if (totalenc > maxgrp) maxgrp = totalenc;
    }
    cout << N - maxgrp << endl;
  }
  return 0;
}
