#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int count[10][n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    for (int j = 0; j < 10; j++) count[j][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    count[arr[i] - 1][i]++;
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 1; j < n; j++) {
      count[i][j] += count[i][j - 1];
    }
  }
  map<int, int> M;
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    M.clear();
    int x = 0, y = 0;
    for (int j = 0; j < 10; j++) {
      if (count[j][i]) M[count[j][i]]++;
      if (x == 0) {
        x = count[j][i];
      } else if (y == 0 && x != count[j][i]) {
        y = count[j][i];
      }
    }
    if (M.size() == 1 && (x == 1 || M[x] == 1)) {
      ans = i + 1;
      break;
    } else if (M.size() == 2) {
      if (x == y - 1 && M[y] == 1) {
        ans = i + 1;
        break;
      }
      if (y == x - 1 && M[x] == 1) {
        ans = i + 1;
        break;
      }
      if (x == 1 && M[x] == 1) {
        ans = i + 1;
        break;
      }
      if (y == 1 && M[y] == 1) {
        ans = i + 1;
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
