#include <bits/stdc++.h>
using namespace std;
long long int sol(long long int arr[]) {
  for (long long int i = 1; i <= 10; i++) {
    if (arr[i] == 0) continue;
    arr[i]--;
    long long int flag = 1;
    long long int tmp = 0;
    for (long long int j = 1; j <= 10; j++) {
      if (arr[j] != 0) {
        tmp = arr[j];
        break;
      }
    }
    for (long long int j = 1; j <= 10; j++) {
      if (arr[j] != 0) {
        if (arr[j] != tmp) {
          flag = 0;
          break;
        }
      }
    }
    if (flag == 1) {
      return 1;
    }
    arr[i]++;
  }
  return 0;
}
int32_t main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  long long int col[11];
  for (long long int i = 1; i <= 10; i++) col[i] = 0;
  for (long long int i = 0; i < n; i++) {
    col[arr[i]]++;
  }
  if (sol(col)) {
    cout << n;
    return 0;
  }
  long long int i = n - 1;
  for (; i >= 0; i--) {
    col[arr[i]]--;
    if (sol(col)) break;
  }
  cout << i;
  return 0;
}
