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