#include <bits/stdc++.h>
using namespace std;
int a[12];
int main() {
  int n, x, ans = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
    vector<int> v;
    for (int j = 1; j <= 10; j++) {
      if (a[j] != 0) {
        v.push_back(a[j]);
      }
    }
    sort(v.begin(), v.end());
    int siz = v.size();
    int cnt1 = 0, cnt2 = 1;
    for (int j = 0; j < siz - 1; j++) {
      if (v[j] + 1 == v[siz - 1]) cnt1++;
    }
    for (int j = 2; j < siz; j++) {
      if (v[j] == v[j - 1]) cnt2++;
    }
    if (v[0] != 1) cnt2 = 0;
    if (cnt1 == siz - 1 || cnt2 == siz - 1) ans = max(ans, i);
  }
  cout << ans << endl;
  return 0;
}
