#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int N = 1e5 + 4, M = N, inf = (int)1e9;
const long long mod = 998244353;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
long long multiply(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
long long sub(long long a, long long b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
map<pair<int, int>, int> mp;
const int dx[4] = {1, 0, 0, -1};
const int dy[4] = {0, -1, 1, 0};
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> h(11, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  int dist = 0;
  int len = 1;
  for (int i = 0; i < n; i++) {
    h[a[i]]++;
    int mflag1 = 1, mflag2 = 1;
    vector<int> hash(11, 0);
    for (int j = 0; j < 11; j++) hash[j] = h[j];
    sort((hash).begin(), (hash).end());
    int id = 1;
    for (int j = 1; j <= 10; j++) {
      if (hash[j] != 0) {
        id = j;
        break;
      }
    }
    if (hash[id] == 1) {
      for (int j = id + 1; j <= 10; j++) {
        if (hash[j] != hash[id + 1]) {
          mflag1 = 0;
          break;
        }
      }
    }
    if (hash[id] != 1) mflag1 = 0;
    for (int j = id; j < 10; j++) {
      if (hash[j] != hash[id]) {
        mflag2 = 0;
        break;
      }
    }
    if (hash[9] + 1 != hash[10]) {
      mflag2 = 0;
    }
    if (mflag1 == 1 || mflag2 == 1) len = max(len, i + 1);
    if (id == 10) len = max(len, i + 1);
  }
  cout << len;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  while (q--) solve();
}
