#include <bits/stdc++.h>
using namespace std;
map<long long, int> vis;
int main() {
  int n;
  cin >> n;
  int num, ans = n - 1;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> num;
    sum += num;
    vis[sum]++;
    ans = min(ans, n - vis[sum]);
  }
  cout << ans << endl;
}
