#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000;
const int MAX_R = 1000000;
const int INF = 1 << 30;
int ls[MAX_N], rs[MAX_N], cs[MAX_R + 1], as[MAX_N];
int main() {
  int n;
  scanf("%d", &n);
  int maxr = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    ls[i] = l, rs[i] = r;
    cs[l]++, cs[r]--;
    if (maxr < r) maxr = r;
  }
  int mint = INF, maxt = 0;
  for (int i = 1; i <= maxr; i++) {
    cs[i] += cs[i - 1];
    if (cs[i] > 2) {
      puts("0");
      return 0;
    }
    if (cs[i] == 2) {
      if (mint > i) mint = i;
      if (maxt < i) maxt = i;
    }
  }
  if (maxt == 0) {
    printf("%d\n", n);
    for (int i = 0; i < n; i++) {
      if (i) putchar(' ');
      printf("%d", i + 1);
    }
    putchar('\n');
  } else {
    int k = 0;
    for (int i = 0; i < n; i++)
      if (ls[i] <= mint && maxt < rs[i]) as[k++] = i;
    printf("%d\n", k);
    if (k > 0) {
      for (int i = 0; i < k; i++) {
        if (i) putchar(' ');
        printf("%d", as[i] + 1);
      }
      putchar('\n');
    }
  }
  return 0;
}
