#include #include #include using namespace std; struct Pair { int start; int end; }; bool compare(Pair a, Pair b) { return a.end < b.end; } int maxPart(vector pairs) { if (pairs.size() < 1) { return 0; } sort(pairs.begin(), pairs.end(), compare); int result = 1; int start = pairs[0].end; for (int i = 1; i < pairs.size(); i++) { if (pairs[i].start >= start) { start = pairs[i].end; result++; } } return result; } int main() { int n; while (cin >> n) { if (n < 1) { continue; } vector pairs; for (int i = 0; i < n; i++) { Pair pair; cin >> pair.start >> pair.end; pairs.push_back(pair); } cout << maxPart(pairs) << endl; } return 0; }