#include <bits/stdc++.h>
using namespace std;
inline void print(char pt) { printf("%c\n", pt); }
inline void print(int pt) { printf("%d\n", pt); }
inline void print(long long pt) { printf("%I64d\n", pt); }
inline void print(double pt) { printf("%f\n", pt); }
inline void print(char pt[]) { printf("%s\n", pt); }
inline void scan(int &pt) { scanf("%d", &pt); }
inline void scan(char &pt) { scanf("%c", &pt); }
inline void scan(long long &pt) { scanf("%I64d", &pt); }
inline void scan(double &pt) { scanf("%lf", &pt); }
inline void scan(char pt[]) { scanf("%s", pt); }
struct pii {
  int a;
  int b;
  friend int operator<(pii a, pii b) {
    if (a.a != b.a) return a.a < b.a;
    return a.b < b.b;
  }
};
struct str {
  char val[55];
  friend int operator<(str a, str b) { return strcmp(a.val, b.val) < 0; }
};
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x * (y / gcd(x, y)); }
int bits[50];
void getbits() {
  for (int i = 0; i < 30; i++) {
    bits[i] = 1 << i;
  }
}
map<long long, int> mapa;
int tmp;
int n;
int main() {
  scan(n);
  long long suma = 0;
  for (int i = 0; i < n; i++) {
    scan(tmp);
    suma += tmp;
    mapa[suma]++;
  }
  int maxa = 0;
  for (auto au : mapa) {
    maxa = max(maxa, au.second);
  }
  print(n - maxa);
  return 0;
}
