#include <bits/stdc++.h>
using namespace std;
int n, ans, col[100005], freq[100005], maxi;
int main() {
  scanf("%d", &n);
  ans = -1;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    freq[col[x]]--;
    col[x]++;
    freq[col[x]]++;
    maxi = max(maxi, col[x]);
    bool val = false;
    if (freq[1] == i + 1)
      val = true;
    else if (freq[i + 1] == 1)
      val = true;
    else if (freq[maxi] * maxi == i)
      val = true;
    else if (freq[maxi - 1] * (maxi - 1) + maxi == i + 1 && freq[maxi] == 1)
      val = true;
    if (val) ans = i;
  }
  ans++;
  printf("%d\n", ans);
  return 0;
}
