#include using namespace std; int le[51], ri[51]; bool mark[51]; bool is_acceptable(int x, int y) { if (le[x] <= y && y <= ri[x]) { if (le[y] <= x && x <= ri[y]) return true; } return false; } int main() { memset(mark, false, sizeof(mark)); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> le[i] >> ri[i]; int ans = 0; for (int i = 0; i < n; i++) { if (mark[i]) continue; // now for person i, we iterate through le[i] to ri[i] and check if they also want to become teammate with them for (int j = max(i + 1, le[i]); j <= ri[i]; j++) { if (mark[j]) continue; if (is_acceptable(i, j)) { // now let's look for a third teammate for (int k = max(j + 1, le[j]); k <= ri[i]; k++) { if (mark[k]) continue; if (is_acceptable(i, k) && is_acceptable(j, k)) { mark[i] = mark[j] = mark[k] = true; ans++; break; } if (mark[k]) break; } } if (mark[j]) break; } if (mark[i]) continue; } cout << ans << endl; }