#include <bits/stdc++.h>
using namespace std;
class B1KoshachyaVecherinkaUproshennayaVersiya {
 public:
  void solve(std::istream& cin, std::ostream& cout) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    int sum[n][10];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 10; ++j) {
        sum[i][j] = 0;
      }
    }
    for (int i = 0; i < n; ++i) {
      sum[i][a[i] - 1]++;
      if (i) {
        for (int j = 0; j < 10; ++j) {
          sum[i][j] += sum[i - 1][j];
        }
      }
    }
    for (int i = n - 1; i >= 0; --i) {
      for (int j = 0; j < 10; ++j) {
        sum[i][j]--;
        bool ok = 1;
        for (int h = 0; h < 10; ++h) {
          for (int k = 0; k < 10; ++k) {
            if (sum[i][k] != sum[i][h] && sum[i][h] != 0 && sum[i][k] != 0) {
              ok = 0;
            }
          }
        }
        if (ok) {
          cout << i + 1 << endl;
          return;
        }
        sum[i][j]++;
      }
    }
    cout << 0 << endl;
  }
};
int main() {
  B1KoshachyaVecherinkaUproshennayaVersiya solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
