#include"bits/stdc++.h" using namespace std; #ifdef ONLINE_JUDGE #define debug(...) 42 #else #include "puppet.h" #endif #include #include using namespace __gnu_pbds; typedef long double ld; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define pob pop_back #define bplc __builtin_popcountll #define bpc __builtin_popcount #pragma GCC optimize("Ofast") #define F first #define S second #define all(v) v.begin(),v.end() #define unique(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) template using pbds= tree,rb_tree_tag, tree_order_statistics_node_update>; template using min_heap=priority_queue, greater>; // *a.find_by_order(x)-->gives xth element considering 0 indexing // a.order_of_key(x)-->gives number of elements strictly smaller than x // struct custom_hash { // static uint64_t splitmix64(uint64_t x) { // // http://xorshift.di.unimi.it/splitmix64.c // x += 0x9e3779b97f4a7c15; // x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; // x = (x ^ (x >> 27)) * 0x94d049bb133111eb; // return x ^ (x >> 31); // } // size_t operator()(uint64_t x) const { // static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); // return splitmix64(x + FIXED_RANDOM); // } // }; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve(){ int n,m; cin>>n>>m; vector>v(m); for(int i=0;i>v[i].F>>v[i].S; sort(all(v)); int l=-2e9,r=2e9; int ans=1; // debug(v); for(auto p:v){ int L=p.F,R=p.S; l=max(l,L); r=min(r,R); debug(L,R); if(l>r){ ans++; l=p.F;r=p.S; } } cout<>T; while(T--){ solve(); } return 0; }