#include <bits/stdc++.h>
using namespace std;
int ara[100002], cnt[11];
int main() {
  int n, i, mx = 0, pr, pr1, c, c1, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &ara[i]);
  for (i = 1; i <= n; i++) {
    cnt[ara[i]]++;
    c = c1 = 0, pr = pr1 = -1;
    for (j = 1; j < 11; j++) {
      if (cnt[j] > 0) {
        if (pr == -1)
          pr = cnt[j], c++;
        else if (pr == cnt[j])
          c++;
        else if (pr1 == cnt[j])
          c1++;
        else {
          if (pr1 == -1)
            pr1 = cnt[j], c1++;
          else {
            pr1 = -2;
            break;
          }
        }
      }
    }
    if (c == i) {
      if (pr == 1) mx = i;
    } else if (c == 1 && pr == i)
      mx = i;
    else if (pr1 != -2 && (c == 1 || c1 == 1)) {
      if (c == 1) {
        if (pr - pr1 == 1)
          mx = i;
        else if (pr == 1)
          mx = i;
      } else {
        if (pr1 - pr == 1)
          mx = i;
        else if (pr1 == 1)
          mx = i;
      }
    }
  }
  printf("%d\n", mx);
  return 0;
}
