#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
long long a[300001];
long long n, m, k;
int b[300001];
void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[x]++;
    b[a[x]] += a[x];
    k = (b[a[x]] >= i && b[a[x]] != n) ? b[a[x]] : k;
  }
  cout << k + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
