#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(11, 0);
  int arr[n];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int ans = 0;
  int l = -1, j = -1, flag = 0;
  int s;
  set<int> sl;
  for (s = 1; s <= n; s++) {
    sl.insert(arr[s]);
    v[arr[s]]++;
    if (sl.size() == 1)
      ans = max(ans, s);
    else if (sl.size() == 2) {
      int first = -1, second = -1;
      for (int i = 1; i <= 10; i++) {
        if (v[i] > 0) {
          if (first == -1)
            first = i;
          else
            second = i;
        }
      }
      if (abs(v[first] - v[second]) == 1) ans = s;
    } else {
      map<int, int> m;
      int flag = 0;
      int first = -1, second = -1;
      for (int i = 1; i <= 10; i++) {
        if (v[i] > 0) {
          m[v[i]]++;
          if (first == -1)
            first = v[i];
          else if (v[i] != first && second == -1)
            second = v[i];
          else if (v[i] != first && v[i] != second) {
            flag = 1;
            break;
          }
        }
      }
      if (flag == 1)
        continue;
      else {
        if (second == -1) {
          if (first == 1) ans = s;
        }
        if (first == second) {
          if (first == 1) ans = s;
        }
        if (second > first) swap(first, second);
        if ((first - second == 1) && m[first] == 1)
          ans = s;
        else if (second == 1 && m[second] == 1)
          ans = s;
      }
    }
  }
  cout << ans << endl;
}
