#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int num_diff = 0;
  int curr_ans = 1;
  unordered_map<int, int> counter;
  unordered_map<int, int> colors;
  for (int i = 1; i <= n; i++) {
    int color;
    scanf("%d", &color);
    if (colors.find(color) == colors.end()) {
      colors[color] = 1;
      counter[1]++;
      num_diff++;
    } else {
      colors[color]++;
      counter[colors[color]]++;
      counter[colors[color] - 1]--;
    }
    if (counter[colors[color]] == num_diff && i != n) {
      curr_ans = i + 1;
    } else if (counter[colors[color]] == num_diff - 1 &&
               counter.find(colors[color] + 1) != counter.end() &&
               counter[colors[color] + 1] == 1) {
      curr_ans = i;
    } else if (counter[colors[color]] == num_diff - 1 && counter[1] == 1) {
      curr_ans = i;
    }
  }
  printf("%d\n", curr_ans);
}
