#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
int b[N];
int main() {
  int n;
  scanf("%d", &n);
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
    b[a[x]]++;
    if (a[x] * b[a[x]] == i && i != n) ans = i + 1;
    if (a[x] * b[a[x]] == i - 1) ans = i;
  }
  cout << ans << endl;
  return 0;
}
