#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int a, b, c, d, e, f, count = 0;
  cin >> a;
  vector<long long int> X(11, 0), A(11, 0), B(a);
  for (b = 0; b < 11; b++) A[b] = 0;
  for (b = 0; b < a; b++) cin >> B[b], A[B[b]]++;
  for (b = 0; b < 11; b++)
    if (A[b] > 0) count++;
  X = A;
  sort(A.begin(), A.end(), greater<int>());
  for (b = a - 1; b >= 0; b--) {
    A[0]--;
    long long int flag = 1;
    for (c = 0; c < count - 1; c++) {
      if (A[c] != A[c + 1]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      cout << b + 1 << endl;
      return 0;
    }
    A[0]++;
    if (A[count - 1] == 1) {
      long long int flag = 1;
      for (c = 0; c < count - 2; c++) {
        if (A[c] != A[c + 1]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        cout << b + 1 << endl;
        return 0;
      }
    }
    X[B[b]]--;
    if (X[B[b]] == 0) count--;
    A = X;
    sort(A.begin(), A.begin() + 11, greater<int>());
  }
  cout << 1 << endl;
}
