#include <bits/stdc++.h>
using namespace std;
int n, cnt, flag = false;
int a[1000100 / 10], b[1000100 / 10], mark[1000100 / 10];
struct Seg {
  int sum0[1000100 * 4], sum1[1000100 * 4], sum2[1000100 * 4];
  int lay[1000100 * 4];
  void pushup(int rt) {
    int L = rt * 2, R = rt * 2 + 1;
    sum0[rt] = sum0[L] + sum0[R];
    sum1[rt] = sum1[L] + sum1[R];
    sum2[rt] = sum2[L] + sum2[R];
  }
  void pushdown(int rt) {
    if (lay[rt]) {
      int L = rt * 2, R = rt * 2 + 1;
      if (lay[rt] > 2) {
        flag = true;
        lay[rt] = 0;
        return;
      }
      if (lay[rt] == 2) {
        if (sum1[L] || sum1[R]) flag = true;
        if (sum2[R] || sum2[L]) flag = true;
        sum2[L] = sum0[L];
        sum2[R] = sum0[R];
        sum0[L] = sum1[L] = 0;
        sum0[R] = sum1[R] = 0;
        lay[L] += lay[rt];
        lay[R] += lay[rt];
        lay[rt] = 0;
        return;
      }
      if (lay[rt] == 1) {
        if (sum2[L] || sum2[R]) flag = true;
        sum2[L] = sum1[L], sum1[L] = sum0[L], sum0[L] = 0;
        sum2[R] = sum1[R], sum1[R] = sum0[R], sum0[R] = 0;
        lay[L] += lay[rt];
        lay[R] += lay[rt];
        lay[rt] = 0;
        return;
      }
    }
  }
  void build(int l, int r, int rt) {
    lay[rt] = 0;
    if (l == r) {
      sum1[rt] = sum2[rt] = 0;
      sum0[rt] = 1;
      return;
    }
    int m = (l + r) / 2;
    build(l, m, rt << 1);
    build(m + 1, r, rt << 1 | 1);
    pushup(rt);
  }
  void update(int L, int R, int l, int r, int rt) {
    if (flag) return;
    if (L <= l && R >= r) {
      if (lay[rt] > 2) return;
      if (sum2[rt]) flag = true;
      sum2[rt] = sum1[rt];
      sum1[rt] = sum0[rt];
      sum0[rt] = 0;
      lay[rt]++;
      if (lay[rt] > 2) flag = true;
      return;
    }
    int m = (l + r) / 2;
    pushdown(rt);
    if (L <= m) update(L, R, l, m, rt << 1);
    if (R > m) update(L, R, m + 1, r, rt << 1 | 1);
    pushup(rt);
  }
  int query(int L, int R, int l, int r, int rt) {
    if (L <= l && R >= r) return sum2[rt];
    pushdown(rt);
    int ans = 0, m = (l + r) / 2;
    if (L <= m) ans += query(L, R, l, m, rt << 1);
    if (R > m) ans += query(L, R, m + 1, r, rt << 1 | 1);
    return ans;
  }
} seg;
int main() {
  int i;
  scanf("%d", &n);
  seg.build(1, 1000100, 1);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    b[i]--;
    seg.update(a[i], b[i], 1, 1000000, 1);
  }
  cnt = 0;
  if (flag) {
    printf("0\n");
    return 0;
  }
  for (i = 1; i <= n; ++i) {
    if (seg.query(a[i], b[i], 1, 1000000, 1) == seg.sum2[1]) mark[i] = 1, cnt++;
  }
  if (flag) {
    printf("0\n");
    return 0;
  }
  printf("%d\n", cnt);
  for (i = 1; i <= n; ++i)
    if (mark[i]) printf("%d ", i);
  printf("\n");
  return 0;
}
