#include <bits/stdc++.h>
using namespace std;
int a[11];
bool check() {
  bool flag = false, ans = true;
  ;
  for (int i = 0; i < 11; i++) {
    if (a[i] != 0) {
      a[i]--;
      int t;
      flag = false;
      ans = true;
      for (int I = 0; I < 11 && ans; I++) {
        if (!flag) {
          if (a[I] != 0) {
            flag = true;
            t = a[I];
          }
        } else {
          if (a[I] != 0 && a[I] != t) ans = false;
        }
      }
      if (ans) return true;
      a[i]++;
    }
  }
  return false;
}
int main() {
  int n, t, Ans;
  bool flag;
  cin >> n;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    cin >> t;
    ans.push_back(t);
    a[t]++;
  }
  Ans = n;
  flag = check();
  for (int i = ans.size() - 1; i > -1 && !flag; i--) {
    Ans--;
    a[ans[i]]--;
    flag = check();
  }
  cout << Ans;
}
