#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int vis[20];
int b[20];
bool ok(int x) {
  int sz = 0, cnt = 1;
  for (int i = 1; i <= 10; i++) {
    if (vis[i]) {
      b[++sz] = vis[i];
    }
  }
  sort(b + 1, b + 1 + sz);
  sz = unique(b + 1, b + 1 + sz) - (b + 1);
  if (sz == 1)
    if (b[1] == 1 || b[1] == x) return 1;
  for (int i = 1; i <= sz; i++) {
    int sta = b[i];
    int num = 0;
    for (int j = 1; j <= 10; j++) {
      if (vis[j] == sta) continue;
      if (vis[j] > sta) {
        num += vis[j] - sta;
      } else {
        num += vis[j];
      }
    }
    if (num == 1) return 1;
  }
  return 0;
}
int main() {
  int n, ans = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    vis[a[i]]++;
    if (ok(i)) {
      ans = i;
    }
  }
  cout << ans;
}
