#include <bits/stdc++.h>
using namespace std;
int ocorrencias[11][100001];
bool caso1(int x) {
  for (int i = 1; i <= 10; i++) {
    if (ocorrencias[i][x] > 1) return false;
  }
  return true;
}
bool caso2(int x) {
  bool found = false;
  int aux = -1;
  for (int i = 1; i <= 10; i++) {
    if (ocorrencias[i][x] == 0) continue;
    if (ocorrencias[i][x] == 1) {
      if (found) return false;
      found = true;
    } else {
      if (aux == -1)
        aux = ocorrencias[i][x];
      else if (ocorrencias[i][x] != aux)
        return false;
    }
  }
  return found;
}
bool caso3(int x) {
  bool found = false;
  int aux = -1;
  for (int i = 1; i <= 10; i++) {
    if (ocorrencias[i][x] == 0) continue;
    if (aux == -1)
      aux = ocorrencias[i][x];
    else if (ocorrencias[i][x] == aux + 1) {
      if (found) return false;
      found = true;
    } else if (ocorrencias[i][x] != aux)
      return false;
  }
  return found;
}
bool caso4(int x) {
  int aux = -1;
  for (int i = 1; i <= 10; i++) {
    if (ocorrencias[i][x] == 0) continue;
    if (aux == -1)
      aux = ocorrencias[i][x] - 1;
    else if (ocorrencias[i][x] != aux)
      return false;
  }
  return true;
}
bool is_valid(int x) {
  bool x1 = caso1(x), x2 = caso2(x), x3 = caso3(x), x4 = caso4(x);
  return x1 || x2 || x3 || x4;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 10; i++) {
    ocorrencias[i][0] = 0;
  }
  int v[100001];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    for (int j = 1; j <= 10; j++) {
      ocorrencias[j][i] = ocorrencias[j][i - 1];
    }
    ocorrencias[v[i]][i]++;
  }
  int x = 1;
  for (int i = 2; i <= n; i++) {
    if (is_valid(i)) x = i;
  }
  printf("%d\n", x);
  return 0;
}
