#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, k;
  cin >> n;
  int a, b[11] = {0};
  vector<int> v;
  vector<int> v1;
  set<int> s;
  for (i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    b[a]++;
  }
  if (n == 1) {
    cout << 1;
    return 0;
  }
  int p = v.size();
  while (p > 0) {
    p--;
    b[v[p]]--;
    int l = 0, y = 0;
    for (i = 1; i <= 10; i++) {
      if (b[i] > 0) {
        v1.push_back(b[i]);
        s.insert(b[i]);
        y++;
      }
      if (b[i] == 1) l++;
    }
    if (s.size() <= 2) {
      int r = 1, t = 0;
      for (i = 1; i < v1.size(); i++) {
        if (v1[0] == v1[i])
          r++;
        else {
          t++;
          k = v1[i];
        }
      }
      if (r == 1 && (v1[0] - k) == 1) {
        cout << p << endl;
        return 0;
      }
      if (t == 1 && (k - v1[0]) == 1) {
        cout << p << endl;
        return 0;
      }
      if (t == 0 || r == 0) {
        cout << p + 1 << endl;
        return 0;
      }
      if (r == 1 && v1[0] == 1) {
        cout << p << endl;
        return 0;
      }
      if (t == 1 && k == 1) {
        cout << p << endl;
        return 0;
      }
    }
    v1.clear();
    s.clear();
  }
}
