#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> f(10);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i] - 1]++;
  }
  int y;
  for (y = n - 1; y >= 0; y--) {
    bool bbroke = false;
    if (y < n - 1) f[a[y + 1] - 1]--;
    vector<int> b(10);
    for (int i = 0; i < 10; i++) b[i] = f[i];
    sort(b.begin(), b.end());
    int r = 0;
    while (b[r] == 0) r++;
    if (r == 9) {
      break;
    } else {
      if (b[r] == 1 && b[r + 1] != 1) {
        bool broke = false;
        for (int i = r + 1; i < 9; i++) {
          if (b[i] != b[i + 1]) {
            broke = true;
            break;
          }
        }
        bbroke = !broke;
      } else {
        bool broke = false;
        for (int i = r; i < 8; i++) {
          if (b[i] != b[i + 1]) {
            broke = true;
            break;
          }
        }
        if (!broke) {
          if (b[9] - b[8] == 1)
            bbroke = true;
          else if (b[r] == 1 && b[9] == 1)
            bbroke = true;
          else
            bbroke = false;
        } else
          bbroke = false;
      }
      if (bbroke) break;
    }
  }
  cout << y + 1 << endl;
}
