#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> a, b;
  int n, i, s = 1, x;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
    b[a[x]]++;
    if (a[x] * b[a[x]] == i && i != n) {
      s = i + 1;
    } else if (a[x] * b[a[x]] == i - 1) {
      s = i;
    }
  }
  cout << s << endl;
}
