#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 1e5 + 9;
int a[19], b[19];
int main() {
  cin >> n;
  int x = 1;
  int mx = 0, tt;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    if (t > 10) continue;
    a[t]++;
    int nb = 0;
    for (int j = 1; j <= 10; j++)
      if (a[j]) b[++nb] = a[j];
    sort(b + 1, b + nb + 1);
    if (nb == 1)
      x = i;
    else {
      bool flag = 1;
      for (int j = 1; j < nb - 1; j++)
        if (b[j] != b[j + 1]) flag = 0;
      if (b[nb - 1] + 1 != b[nb]) flag = 0;
      if (b[1] == 1 && !flag) {
        flag = 1;
        for (int j = 2; j < nb; j++)
          if (b[j] != b[j + 1]) flag = 0;
      }
      if (flag) x = i;
    }
  }
  cout << x << endl;
  return 0;
}
