#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  long long n, ans = 1000000007, sum = 0;
  cin >> n;
  map<long long, int> c;
  ans = n - 1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    c[sum]++;
    ans = min(ans, n - c[sum]);
  }
  cout << ans;
  return 0;
}
