#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
long long sum[500050];
int a[500050];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[i + n] = a[i];
  }
  for (int i = 1; i <= 2 * n; ++i) sum[i] = sum[i - 1] + a[i];
  for (int i = 1; i <= n; ++i) {
    if (!mp.count(sum[i]))
      mp[sum[i]] = 1;
    else
      mp[sum[i]]++;
  }
  int ans = mp[0];
  for (int i = n + 1; i < 2 * n; ++i) {
    mp[sum[i - n]]--;
    if (!mp.count(sum[i]))
      mp[sum[i]] = 1;
    else
      mp[sum[i]]++;
    ans = max(ans, mp[sum[i - n]]);
  }
  printf("%d\n", n - ans);
}
