#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
inline int L(int x) { return 2 * x; }
inline int R(int x) { return 2 * x + 1; }
struct node {
  int L, R;
  pair<int, int> mx;
  int lazy;
};
node tree[4 * 2 * MAXN];
vector<int> vec;
vector<pair<int, int> > seg;
int N;
int compress(int x) {
  return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1;
}
void init(int l, int r, int at) {
  tree[at].L = l;
  tree[at].R = r;
  tree[at].mx = pair<int, int>(0, l);
  if (l == r) return;
  int mid = (l + r) / 2;
  init(l, mid, L(at));
  init(mid + 1, r, R(at));
}
void push(int at) {
  if (tree[at].lazy != 0) {
    tree[at].mx.first += tree[at].lazy;
    if (tree[at].L != tree[at].R) {
      tree[L(at)].lazy += tree[at].lazy;
      tree[R(at)].lazy += tree[at].lazy;
    }
    tree[at].lazy = 0;
  }
}
void refresh(int at) {
  push(at);
  if (tree[at].L != tree[at].R) {
    push(L(at));
    push(R(at));
    if (tree[L(at)].mx > tree[R(at)].mx) {
      tree[at].mx = tree[L(at)].mx;
    } else {
      tree[at].mx = tree[R(at)].mx;
    }
  }
}
void update(int ql, int qr, int at, int delta) {
  push(at);
  if (tree[at].L >= ql && tree[at].R <= qr) {
    tree[at].lazy += delta;
    push(at);
    return;
  }
  int mid = (tree[at].L + tree[at].R) / 2;
  if (ql <= mid) update(ql, qr, L(at), delta);
  if (qr > mid) update(ql, qr, R(at), delta);
  refresh(at);
}
pair<int, int> query(int ql, int qr, int at) {
  push(at);
  if (tree[at].L >= ql && tree[at].R <= qr) {
    return tree[at].mx;
  }
  int mid = (tree[at].L + tree[at].R) / 2;
  pair<int, int> ret(INT_MIN, 0);
  if (ql <= mid) ret = max(ret, query(ql, qr, L(at)));
  if (qr > mid) ret = max(ret, query(ql, qr, R(at)));
  refresh(at);
  return ret;
}
int main(int argc, char *argv[]) {
  scanf("%d", &N);
  seg.reserve(N);
  seg.reserve(2 * N);
  init(1, 2 * (N + 1), 1);
  for (int i = 0, _i = N; i < _i; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    seg.push_back(pair<int, int>(a, b - 1));
    vec.push_back(a);
    vec.push_back(b - 1);
  }
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (int i = 0, _i = N; i < _i; ++i) {
    seg[i].first = compress(seg[i].first);
    seg[i].second = compress(seg[i].second);
    update(seg[i].first, seg[i].second, 1, 1);
  }
  vector<int> ans;
  ans.reserve(N);
  for (int i = 0, _i = N; i < _i; ++i) {
    update(seg[i].first, seg[i].second, 1, -1);
    if (query(1, 2 * N, 1).first <= 1) ans.push_back(i + 1);
    update(seg[i].first, seg[i].second, 1, 1);
  }
  printf("%d\n", ans.size());
  for (int i = 0, _i = ans.size(); i < _i; ++i) {
    printf("%d ", ans[i]);
  }
  return 0;
}
