#include <bits/stdc++.h>
using namespace std;
long long n, x, c, res, d[100005] = {0}, ans;
vector<long long> vt, v;
bool kt;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0, ThxDem = n; i < ThxDem; i++) {
    kt = true;
    c = 0;
    v.clear();
    cin >> x;
    if (d[x] == 0) vt.push_back(x);
    d[x]++;
    for (long long j = 0, ThxDem = vt.size(); j < ThxDem; j++)
      v.push_back(d[vt[j]]);
    sort(v.begin(), v.end());
    if (v.size() > 1) {
      if (v[0] == 1 && v[1] != 1) {
        res = v[1];
        for (long long j = 2, ThxDem = v.size(); j < ThxDem; j++)
          if (v[j] != res) {
            kt = false;
            break;
          }
      } else if (v[v.size() - 1] - 1 == v[v.size() - 2]) {
        res = v[v.size() - 2];
        for (long long j = 0, ThxDem = v.size() - 2; j < ThxDem; j++)
          if (v[j] != res) {
            kt = false;
            break;
          }
      } else if (v[0] == v[v.size() - 1] && v[0] == 1)
        ;
      else
        kt = false;
    }
    if (kt) ans = i + 1;
  }
  cout << ans;
  return 0;
}
