#include <bits/stdc++.h>
using namespace std;
int n, a[100005], cnt[11], num[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int k = 0, q = 0;
  num[0] = 10;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    num[cnt[a[i]]]--;
    cnt[a[i]]++;
    num[cnt[a[i]]]++;
    q = max(q, cnt[a[i]]);
    if (q == 1 || num[q] == 1 && (num[q - 1] + 1) * (q - 1) == i - 1 ||
        num[1] == 1 && num[q] * q == i - 1)
      k = i;
  }
  cout << k << endl;
  return 0;
}
