#include <bits/stdc++.h>
using namespace std;
const long long MOD = 9973;
map<long long, int> mp;
int x, n;
long long ans = 0, sum = 0, ansi;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    sum += x;
    if (mp.find(sum) == mp.end())
      mp[sum] = 1;
    else
      mp[sum] += 1;
    if (mp[sum] > ans) ans = mp[sum], ansi = sum;
  }
  ans = n - ans;
  cout << ans << endl;
}
