#include <bits/stdc++.h>
using namespace std;
const unsigned long long base = 131;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
const long double eps = 1e-7;
const int mod = 1e9 + 7;
const int M = 1e5 + 10;
int a[M], cnt[M], tot, n, mx, mn = inf, pos;
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  if (n == 1) return 0 * printf("1\n");
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  for (int i = n; i >= 1; i--) {
    for (int k = 1; k <= 10; k++) {
      if (cnt[k] == 0) continue;
      cnt[k]--;
      mx = 0, mn = inf;
      for (int j = 1; j <= 10; j++)
        if (cnt[j]) {
          mn = min(mn, cnt[j]);
          mx = max(mx, cnt[j]);
        }
      cnt[k]++;
      if (mn == mx) {
        printf("%d\n", i);
        return 0;
      }
    }
    cnt[a[i]]--;
  }
  return 0;
}
