#include <bits/stdc++.h>
const int N = 5000 + 10;
struct node {
  int l, r, id;
};
node a[N];
bool pre[N], suf[N];
std::vector<node> vector;
bool cmp(const node& i, const node& j) {
  if (i.r ^ j.r)
    return i.r < j.r;
  else
    return i.l < j.l;
}
bool cc(const node& i, const node& j) { return i.id < j.id; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    a[i].id = i;
    scanf("%d%d", &a[i].l, &a[i].r);
  }
  std::sort(a + 1, a + 1 + n, cmp);
  pre[0] = pre[1] = true;
  for (int i = 2; i <= n; ++i)
    if (pre[i - 1] && a[i].l >= a[i - 1].r)
      pre[i] = true;
    else
      break;
  suf[n + 1] = suf[n] = true;
  for (int i = n - 1; i >= 1; --i)
    if (suf[i + 1] && a[i].r <= a[i + 1].l)
      suf[i] = true;
    else
      break;
  for (int i = 1; i <= n; ++i)
    if (pre[i - 1] && suf[i + 1]) {
      if (i == 1 || i == n || a[i - 1].r <= a[i + 1].l) vector.push_back(a[i]);
    }
  std::sort(vector.begin(), vector.end(), cc);
  printf("%d\n", vector.size());
  for (int i = 0; i < vector.size(); ++i) {
    if (i) putchar(' ');
    printf("%d", vector[i].id);
  }
  puts("");
  return 0;
}
