#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int t;
  cin >> t;
  int ans, answer;
  vector<int> v;
  int n, arr[11] = {};
  for (int i = 0; i < t; i++) {
    cin >> n;
    int j = 1, ch = 0;
    arr[n]++;
    v.clear();
    for (int j = 0; j < 11; j++) v.push_back(arr[j]);
    sort(v.begin(), v.end(), cmp);
    ans = v[0];
    if (v[0] == 1)
      answer = i + 1;
    else if (v[j] != ans) {
      ans = v[0];
      while (v[j]) {
        if (v[j] != ans - 1) {
          ch = 1;
          break;
        }
        j++;
      }
      if (ch == 1)
        continue;
      else
        answer = i + 1;
    } else {
      ans = v[0];
      while (v[j]) {
        if (v[j] != ans) {
          ch = 1;
          break;
        }
        j++;
      }
      if (ch == 1 && v[j] == 1 && v[j + 1] == 0)
        answer = i + 1;
      else {
        continue;
      }
    }
  }
  cout << answer;
  cout << '\n';
  return 0;
}
