#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N,M; cin >> N >> M; vector> seg(M); for(auto &[a, b] : seg) cin >> a >> b; sort(seg.begin(), seg.end(), [](pair I, pair J) { if(I.second == J.second) return I.first < J.first; return I.second < J.second; }); int LAST = -1e9, cnt = 0; for(auto [a, b] : seg) { if(LAST <= a) { cnt++; LAST = b; } } cout << 2 * (N - 1) - cnt << endl; }