#include <bits/stdc++.h>
using namespace std;
const int MAXN(1e5 + 100), INF(0x3f3f3f3f);
const long long INFLL(0x3f3f3f3f3f3f3f3f);
int n, ans;
map<int, int> mp;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
bool check() {
  map<int, int> tmp;
  for (pair<int, int> p : mp) tmp[p.second]++;
  if (tmp.size() == 1) return tmp.count(1) || tmp.begin()->second == 1;
  if (tmp.size() > 2) return false;
  if (tmp.count(1) && tmp[1] == 1) return true;
  auto iter1 = tmp.begin();
  auto iter2 = tmp.begin();
  iter2++;
  return iter1->first == iter2->first - 1 && iter2->second == 1;
}
void init() { n = read(); }
void solve() {
  for (int i = 1; i <= n; i++) {
    int col = read();
    mp[col]++;
    if (check()) ans = i;
  }
  printf("%d\n", ans);
}
int main() {
  {
    init();
    solve();
  }
}
