#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0};
int dy[] = {0, 0, 1, -1, 0, 0, 0, 0};
const long long inf = 100000007;
const double eps = 0.000000009;
long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  int f[10];
  memset(f, 0, sizeof(f));
  int p = 0;
  while (p < n) {
    f[a[p]]++;
    map<int, int> s;
    for (int i = 0; i < 10; i++) {
      if (f[i]) s[f[i]]++;
    }
    if (s.size() == 2) {
      map<int, int>::iterator it = s.begin();
      pair<int, int> x = *it;
      it++;
      pair<int, int> y = *it;
      if ((y.first - x.first == 1 && y.second == 1) ||
          (x.first == 1 && x.second == 1))
        ans = p + 1;
    } else if (s.size() == 1) {
      map<int, int>::iterator it = s.begin();
      pair<int, int> x = *it;
      if (x.first == 1 || x.second == 1) ans = p + 1;
    }
    p++;
  }
  cout << ans << endl;
  return 0;
}
