#include <bits/stdc++.h>
using namespace std;
int cnt[11];
bool check() {
  int i, c = 0;
  bool f = 1;
  map<int, int> m;
  for (i = 0; i < 11; i++) {
    if (cnt[i] != 0) {
      m[cnt[i]]++;
      c++;
      if (cnt[i] != 1) f = 0;
    }
  }
  int size = m.size();
  if (size == 1) {
    if (c == 1 || f) {
      return 1;
    } else {
      return 0;
    }
  } else if (size > 2) {
    return 0;
  } else if (size == 2) {
    int x = 0;
    int a, s, l, r;
    for (auto p : m) {
      if (x == 0) {
        a = p.first;
        s = p.second;
      } else {
        l = p.first;
        r = p.second;
      }
      x++;
    }
    if ((a == 1 && s == 1) || (l == 1 && r == 1)) {
      return 1;
    } else {
      if (abs(a - l) == 1 && min(l, r) == 1) {
        return 1;
      }
      return 0;
    }
  }
  return 0;
}
int main() {
  int n, i;
  cin >> n;
  int arr[n];
  for (i = 0; i < n; i++) {
    int k;
    cin >> k;
    cnt[k]++;
    arr[i] = k;
  }
  for (i = n - 1; i >= 0; i--) {
    if (check()) {
      cout << i + 1;
      cout << "\n";
      return 0;
    }
    cnt[arr[i]]--;
  }
  return 0;
}
