#include <bits/stdc++.h>
using namespace std;
long long n, arry[100010], sum[100010];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> arry[i];
    sum[i] = sum[i - 1] + arry[i];
  }
  sort(sum + 1, sum + 1 + n);
  long long mlen = 1, pre = 1;
  for (int i = 2; i <= n; ++i) {
    if (sum[i] == sum[i - 1])
      pre++;
    else
      pre = 1;
    if (pre > mlen) mlen = pre;
  }
  cout << n - mlen << endl;
}
