1. Abridged Problem Statement  
Given N intervals [Ai, Bi] with all Ai distinct and all Bi distinct, an interval i is called redundant if there exists another interval j such that Aj < Ai and Bi < Bj. Count how many intervals are redundant.

2. Detailed Editorial  
Problem Restatement  
- We have N defense outposts along a border, each covering a segment [Ai, Bi].  
- We want to abandon every “redundant” outpost, where an outpost i is redundant if it is strictly contained in some earlier-starting, later-ending segment j (i.e., Aj < Ai and Bi < Bj).  
- Output the total number of redundant outposts.

Key Observations  
- Since all Ai are distinct, sorting intervals by Ai gives a strict increasing order of starts.  
- While scanning in increasing order of Ai, any candidate interval i can only be contained in some interval j with a smaller start—i.e., one of the intervals we have already seen.  
- Among all previously seen intervals, the one with the largest end Bmax is the “widest” and thus most likely to contain the current interval.  
- If current Bi < Bmax, then there exists some earlier interval j with Bj = Bmax > Bi, so i is redundant. Otherwise, update Bmax to Bi.

Algorithm  
1. Read N and the list of (Ai, Bi).  
2. Sort the list by Ai in ascending order.  
3. Initialize Bmax = −∞ and answer = 0.  
4. For each interval in sorted order:  
   a. If Bi < Bmax, increment answer (interval is redundant).  
   b. Else, set Bmax = Bi (this interval extends the maximum coverage).  
5. Print answer.

Correctness  
- Sorting ensures that when processing interval i, all j with Aj < Ai have been considered.  
- Keeping only Bmax is sufficient: if any previous interval j had Bj > Bi, then Bmax ≥ Bj > Bi; so checking Bi < Bmax detects redundancy.  
- Distinctness of Ai and Bi avoids edge cases of ties.

Complexity  
- Sorting: O(N log N)  
- Linear scan: O(N)  
- Total: O(N log N), which is efficient for N up to 16 000.

3. C++ Solution
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<pair<int, int>> a;

void read() {
    cin >> n;
    a.resize(n);
    cin >> a;
}

void solve() {
    /*
     * Outpost i is redundant iff some j has A[j] < A[i] and B[i] < B[j]. Sort
     * the intervals by left endpoint A ascending; then while scanning we track
     * mx = the largest right endpoint B among all already-seen outposts (which
     * all have strictly smaller A). The current outpost is redundant exactly
     * when its B is below mx. All A and all B are distinct, so no ties matter.
     */

    sort(a.begin(), a.end());
    int answer = 0;
    int mx = INT_MIN;
    for(int i = 0; i < n; i++) {
        if(a[i].second < mx) {
            answer++;
        }

        mx = max(mx, a[i].second);
    }

    cout << answer << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution with Detailed Comments  
```python
import sys

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    n = int(next(it))
    intervals = []

    # Read all intervals
    for _ in range(n):
        A = int(next(it))
        B = int(next(it))
        intervals.append((A, B))

    # Sort by start A ascending
    intervals.sort(key=lambda x: x[0])

    Bmax = -10**18   # track the maximum end seen so far
    answer = 0       # count of redundant intervals

    # Sweep through intervals
    for A, B in intervals:
        # If this interval ends before Bmax, it's redundant
        if B < Bmax:
            answer += 1
        else:
            # Otherwise update Bmax
            Bmax = B

    # Print final count
    print(answer)

if __name__ == "__main__":
    main()
```

5. Compressed Editorial  
1. Sort intervals by start.  
2. Maintain the maximum end Bmax of processed intervals.  
3. For each interval, if its end < Bmax, it is redundant; otherwise update Bmax.  
4. Count and output redundancies.