#include <bits/stdc++.h>
using namespace std;
int amp[200005];
bool isrp[20];
int as[20], it, mp[20];
int main() {
  int n;
  cin >> n;
  int res = 1;
  for (int i = 1; i <= n; i++) {
    cin >> amp[i];
  }
  for (int j = 1; j <= n; j++) {
    mp[amp[j]]++;
    isrp[amp[j]] = true;
    memset(as, 0, sizeof(as));
    it = 1;
    for (int i = 1; i <= 10; i++) {
      if (isrp[i]) {
        as[it++] = mp[i];
      }
    }
    it--;
    if (it == 1) {
      res = j;
      continue;
    }
    sort(as + 1, as + it + 1);
    int k = as[it];
    bool flag = true;
    for (int i = 1; i < it; i++) {
      if (as[i] != k - 1) flag = false;
    }
    if (flag) res = j;
    if (!flag && as[1] == 1) {
      flag = true;
      for (int i = it; i >= 3; i--) {
        if (as[i] != as[i - 1]) flag = false;
      }
      if (flag) res = j;
    }
  }
  cout << res << endl;
  return 0;
}
