#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int num[N][11];
int a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    num[i][a[i]] = num[i - 1][a[i]] + 1;
    for (int j = 1; j <= 10; j++) {
      if (j != a[i]) num[i][j] = num[i - 1][j];
    }
  }
  int id = 1;
  for (int x = 2; x <= n; x++) {
    vector<int> now;
    for (int j = 1; j <= 10; j++) {
      if (num[x][j]) now.push_back(num[x][j]);
    }
    sort(now.begin(), now.end());
    if ((now[1] == now[now.size() - 1] && now[0] == 1) ||
        ((now[now.size() - 1] == now[now.size() - 2] + 1) &&
         (now[now.size() - 2] == now[0])) ||
        (now.size() == 1))
      id = x;
  }
  cout << id << endl;
  return 0;
}
