#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 1e5 + 5;
int maxn, cnts;
int n, a[N], b[N], c[N], is[N];
bool check() {
  for (int i = 1; i <= maxn; i++) c[i] = b[i];
  sort(c + 1, c + 1 + maxn);
  for (int i = 1; i <= maxn; i++) {
    if (c[i] == 0) continue;
    if (i == maxn) return 1;
    for (int j = i + 1; j <= maxn; j++)
      if (c[j] != c[i]) return 0;
    return 1;
  }
}
signed main() {
  scanf("%d", &n);
  maxn = 0, cnts = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), b[a[i]]++, maxn = max(maxn, a[i]);
  for (int i = n; i; i--) {
    for (int j = 1; j <= maxn; j++) {
      if (b[j]) {
        b[j]--;
        if (check()) return printf("%d\n", i), 0;
        b[j]++;
      }
    }
    b[a[i]]--;
  }
}
