#include <bits/stdc++.h>
const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;
template <typename T>
void debug(vector<T> &vec) {
  for (auto x : vec) {
    cout << x << " ";
  }
  cout << endl;
  return;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
int main() {
  int n;
  cin >> n;
  vector<int> u(n), cnt(10, 0);
  for (int i = 0; i < n; i++) {
    cin >> u[i];
    cnt[u[i] - 1] += 1;
  }
  for (int i = n - 1; i > -1; i--) {
    for (int num = 1; num <= 10; num++) {
      bool areSame = true;
      int tmp = 0;
      if (cnt[num - 1] == 0) continue;
      cnt[num - 1] -= 1;
      for (int j = 0; j < 10; j++) {
        if (cnt[j] == 0) continue;
        tmp = cnt[j];
        break;
      }
      for (int c = 0; c < 10; c++) {
        if (cnt[c] == tmp || cnt[c] == 0) continue;
        areSame = false;
      }
      if (areSame) {
        cout << i + 1 << endl;
        return 0;
      }
      cnt[num - 1] += 1;
    }
    cnt[u[i] - 1] -= 1;
  }
  return 0;
}
