#include <bits/stdc++.h>
using namespace std;
int dr[8] = {-1, 0, +1, 0, -1, -1, +1, +1};
int dc[8] = {0, +1, 0, -1, -1, +1, -1, +1};
int kx[8] = {-1, +1, +1, -1, +2, +2, -2, -2};
int ky[8] = {+2, +2, -2, -2, -1, +1, +1, -1};
const int N = 100005;
int main() {
  int n, x;
  cin >> n;
  map<int, int> mm;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    mm[x]++;
    vector<int> ss;
    set<int> s1;
    for (int j = 1; j <= 10; ++j) {
      if (!mm[j]) continue;
      ss.push_back(mm[j]);
      s1.insert(mm[j]);
    }
    sort(ss.begin(), ss.end());
    int nn = ss.size();
    int cnt = 0;
    for (int j : ss) {
      if (j == 1) cnt++;
    }
    if (s1.size() > 2)
      continue;
    else if (nn == 1) {
      ans = i;
    } else if (cnt == nn) {
      ans = i;
    } else if (cnt == 1) {
      ans = i;
    } else if (ss[nn - 1] - ss[nn - 2] == 1) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
