#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b) return (gcd(b, a));
  if (b == 0) return a;
  return gcd(b, a % b);
}
int a[100002], b[100002];
int main() {
  int n, i, r, ans = 0;
  cin >> n;
  if (n == 1) {
    cout << 1;
    return (0);
  }
  for (i = 1; i <= n; i++) {
    cin >> r;
    a[r]++;
    b[a[r]] = b[a[r]] + a[r];
    if (b[a[r]] == i && i < n)
      ans = i + 1;
    else if (b[a[r]] == (i - 1))
      ans = i;
  }
  cout << ans;
}
