#include <bits/stdc++.h>
using namespace std;
bool equal_range(int *arr, int a, int b) {
  for (int i = a; i < b - 1; i++) {
    if (arr[i] != arr[i + 1]) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> cnt(11);
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    int c;
    cin >> c;
    cnt[c]++;
    int cur[11];
    cur[0] = 0;
    for (int j = 1; j <= 10; j++) {
      cur[j] = cnt[j];
    }
    sort(cur, cur + 11);
    int st = 0;
    while (!cur[st]) {
      st++;
    }
    if (st == 10 || cur[st] == 1 && equal_range(cur, st + 1, 11) ||
        equal_range(cur, st, 10) && cur[10] == cur[9] + 1) {
      ans = i;
    }
  }
  cout << ans;
  return 0;
}
