#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e14;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t = 1, n, x;
  while (t--) {
    cin >> n;
    long long ans = 1;
    map<long long, long long> mp1, mp2;
    for (long long i = 1; i < n + 1; ++i) {
      cin >> x;
      mp1[x]++, mp2[mp1[x]]++;
      if (mp1[x] * mp2[mp1[x]] == i && i != n)
        ans = i + 1;
      else if (mp1[x] * mp2[mp1[x]] == i - 1)
        ans = i;
    }
    cout << ans << '\n';
  }
}
