#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; V L(n),R(n); rep(i,n) cin>>L[i]>>R[i]; V> P(n); rep(i,n) P[i]={R[i],L[i]}; sort(ALL(P)); stack> st; rep(i,n){ if(st.empty()) st.push(P[i]); else if(st.top().first<=P[i].second) st.push(P[i]); } cout<