#include <bits/stdc++.h>
using namespace std;
int n, s[100010];
map<long long, int> mp;
int main() {
  while (scanf("%d", &n) != EOF) {
    mp.clear();
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
    long long tmp = 0;
    long long sum[100010];
    memset(sum, 0, sizeof(sum));
    for (int i = 0; i < n; i++) {
      tmp += s[i];
      sum[i] = tmp;
      mp[tmp]++;
    }
    long long res = -1;
    for (int i = 0; i < n; i++) {
      if (res == -1 || res < mp[sum[i]]) res = mp[sum[i]];
    }
    printf("%I64d\n", n - res);
  }
  return 0;
}
