#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  ;
  vector<long long> u(11), v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    u[v[i]]++;
  }
  long long ans = -1;
  for (long long i = n - 1; i >= 0; i--) {
    set<long long> s;
    for (long long i = 1; i <= 10; i++) {
      if (u[i] > 0) s.insert(u[i]);
    }
    if (s.size() == 1) {
      long long cnt = 0;
      long long val = 0;
      for (auto i : s) val = i;
      for (long long i = 1; i <= 10; i++) {
        if (u[i] > 0) {
          if (u[i] == val) cnt++;
        }
      }
      if (cnt == 1) {
        ans = i + 1;
        break;
      }
      if (val == 1) {
        ans = i + 1;
        break;
      }
    }
    if (s.size() == 2) {
      long long c = 0;
      long long a[2];
      for (auto i : s) {
        a[c] = i;
        c++;
      }
      long long cnt1 = 0, cnt2 = 0;
      for (long long i = 1; i <= 10; i++) {
        if (u[i] > 0) {
          if (u[i] == a[0])
            cnt1++;
          else if (u[i] == a[1])
            cnt2++;
        }
      }
      if (cnt1 == 1 && a[0] == 1) {
        ans = i + 1;
        break;
      }
      if (cnt2 == 1 && a[1] == (a[0] + 1)) {
        ans = i + 1;
        break;
      }
    }
    u[v[i]]--;
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
