#include <bits/stdc++.h>
using namespace std;
int f[15], aux[15], nraux;
int ok() {
  int i, val, p1, pm, ok1 = 0, ok2 = 0;
  nraux = 0;
  p1 = 0;
  pm = 0;
  for (i = 1; i <= 10; i++)
    if (f[i] != 0) {
      nraux++;
      aux[nraux] = f[i];
    }
  if (nraux == 1) return 1;
  val = aux[1];
  for (i = 2; i <= nraux; i++)
    if (aux[i] == val)
      ;
    else if ((aux[i] == val + 1) || (aux[i] == 1))
      p1++;
    else
      pm++;
  if ((pm == 0) && (p1 == 1)) ok1 = 1;
  if ((nraux > 1) && ((aux[1] == aux[2] + 1) || (aux[1] == 1))) {
    val = aux[2];
    p1 = 0;
    pm = 0;
    for (i = 2; i <= nraux; i++)
      if (aux[i] != val) pm++;
    if (pm == 0) ok2 = 1;
  }
  return (ok1 || ok2);
}
int n, a[100005];
int main() {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  for (i = n; i >= 2; i--) {
    if (ok()) {
      cout << i;
      return 0;
    }
    f[a[i]]--;
  }
  cout << 1;
  return 0;
}
