stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
/*

TLE発生

原因はvectorのreverseかな？

*/





#include <bits/stdc++.h>

using namespace std;



using LL = long long;



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);



    LL n;

    cin >> n;

    vector<LL> a(n);

    for (int i = 0; i < n; i++){

        cin >> a[i];

    }



    vector<LL> b;

    b.reserve(n);



    if(n == 1){

        cout << a[0] << endl;

        return 0;

    }



    for (int i = 0; i < n; i = i + 2){

        b.push_back(a[i]);

    }

    reverse(b.begin(), b.end());

    for (int i = 1; i < n; i = i + 2){

        b.push_back(a[i]);

    }

    if(n % 2 == 0){

        reverse(b.begin(), b.end());

    }



    for (int i = 0; i < n; i++){

        cout << b[i] << " ";

    }



    cout << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;



long long int* sat(long long int*a,long long int *b,int n)

{

	for(int j=0;j<n;j++)

	{

		b[j]=a[j];

	} 

	for(int k=0;k<n;k++)

	{

		a[k]=b[n-1-k]; 

	}

	return a;

}



int main(void)

{

	int n = 0;

	cin>>n;

	long long int a[n]={0};

	long long int b[n] ={0};

	

	for(int k=0;k<n;k++){

		long long int h =0;

		cin>>h;

		a[k]=h;

	}



	if(n%2 == 0)

	{

		for(int i=0;i<n/2;i++)

		{

			b[i]=a[n-1-2*i];

		}

		for(int j=n/2;j<n;j++)

		{

			b[j]=a[2*(j-n/2)];

		}

	}else

	{

		for(int i=0;i<(n+1)/2;i++)

		{

			b[i]=a[n-1-2*i];

		}

		for(int j=(n+1)/2;j<n;j++)

		{

			b[j]=a[2*(j-(n+1)/2)+1];

		}

	}



	for (int o=0;o<n;o++)

	{

		cout<<b[o]<<" ";

	}

	



	return 0;

}








// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define rep(i,l,p) for(int i = l; i<=p; i++)

#define drep(i,p,l) for(int i = p; i>=l; i++)

using namespace std;



int n;

struct node

{

	int val;

	node *front,*after;

	node(){

		front = NULL;

		after = NULL;

		val = -1;

	}



	node(node* inifront, int inival,node* iniafter){

		val = inival;

		after = iniafter;

		front = inifront;

	}

};



node* first = new node();

node* last = new node();





void lastPlus(int val){

	node *tmp = last->front;

	last->front = new node(last->front,val,last);

	if(tmp != NULL) tmp->after = last->front;

}



void firstPlus(int val){

	node *tmp = first->after;

	first->after = new node(first,val,first->after);



	if(tmp != NULL)tmp->front = first->after;

}

void conbine(){

	node* tmp1 = first;

	while(tmp1->after != NULL){

		tmp1 = tmp1->after;

	//	printf("%d ", tmp1->val);

	}

	//printf("\n");

	

	node* tmp2 = last;

	while(tmp2->front != NULL){

		tmp2 = tmp2->front;

	//	printf("%d ",tmp2->val);

	}

	//printf("\n");



	tmp1->after = tmp2;

	tmp2->front = tmp1;

	//printf("conbine:\n");



//	tmp1 = first;

	// rep(i,1,n){ 

	// 	printf("%d ",tmp1->val);

	// 	tmp1 = tmp1->after;

		

//	}

}

void outputfirst(){

	node* tmp;



	tmp = first->after;

	rep(i,1,n){

		printf("%d ",tmp->val);

		tmp = tmp->after;

	}

}

void outputlast(){

	node *tmp = last->front;

	rep(i,1,n){

		printf("%d ",tmp->val);

		tmp = tmp->front;

	}

}

int main(){

	scanf("%d",&n);

	int t;

	rep(i,1,n){

		scanf("%d",&t);

		if( i % 2 == 1){

			lastPlus(t);

		}else firstPlus(t);

	}

	conbine();

	t = (n+1) % 2 ;

	if ( t == 1){

		outputfirst();

	}else {

		outputlast();

	}



	 return 0;



}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h> 

using namespace std; 

int main() 

{ 	

	cin.tie(0); 	

	cout.tie(0); 

	ios::sync_with_stdio(false); 

	int count; 	

	cin >> count; 

	int *a = new int[count]; 	

	for(int i = 0; i < count; i++)

	{

		cin >> a[i]; 

	}	

	

	deque<int> dq; 

	for (int i = 0; i < count; i++) 

	{ 		

		if (i % 2 == 0) 		

		dq.push_front(a[i]); 

		if (i % 2 == 1) 	

		dq.push_back(a[i]); 

	} 

	if (count % 2 != 0) 	

	{ 	

		for (int i = 0; i < dq.size(); i++) 		

		{ 			cout << dq[i] << " "; 		} 	

	} 

	else 

	{ 	

		for (int i = dq.size()-1; i >=0; i--) 	

		{ 			

		cout << dq[i] << " "; 	

		} 

	} 	

	return 0; 

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;



int main() {



	int length;

	cin >> length;

	int *a = new int[length];

	int *b = new int[length];

	for (int i = 0; i < length; i++) {

		cin >> a[i];

	}



	int left = 0, right = length - 1;

	if (length % 2 == 0) {

		for (int i = length - 1; i > 0; i -= 2) {

			b[left++] = a[i];

			b[right--] = a[i - 1];

		}

	}

	else {

		for (int i = length - 1; i > 0; i -= 2) {

			b[left++] = a[i];

			b[right--] = a[i - 1];

		}

		b[length / 2] = a[0];

	}





	for (int i = 0; i < length; i++) {

		cout << b[i] << " ";

	}

}






// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <list>

#include <iostream>

#include <algorithm>

using namespace std;



int main()

{

    int n;

    cin >> n;

    bool flag=true;

    list<int> mylist;

    int t;

    for(int i=0;i<n;++i)

    {

        cin >> t;

        if(flag)

        {

            mylist.push_front(t);

        } else {

            mylist.push_back(t);

        }

        flag=!flag;

    }



    flag=n%2;



    if(flag)

    {

        for(auto it=mylist.begin();it!=mylist.end();++it)

        {

            cout << *it << ' ';



        }

    } else {

        for(auto it=mylist.rbegin();it!=mylist.rend();++it)

        {

            cout << *it << ' ';



        }

    }



	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main()

{

	int n,temp;

	list<int> l;

	while(~scanf("%d",&n)){

		l.clear();

		for(int i=0;i<n;++i){

			scanf("%d",&temp);

			if(i&1){

				l.push_front(temp);

			}else{

				l.push_back(temp);

			}

		}

		if(n&1){

			list<int>::reverse_iterator a,b;

			a=l.rbegin(),b=l.rend();

			printf("%d",*a);

			++a;

			for(;a!=b;++a){

				printf(" %d",*a);

			}

		}else{

			list<int>::iterator a,b;

			a=l.begin(),b=l.end();

			printf("%d",*a);

			++a;

			for(;a!=b;++a){

				printf(" %d",*a);

			}

		}

		putchar('\n');

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;



const int M = 2e5;

int a[M];

int main()

{

	

	int n;

	while (cin >> n)

	{

		for (int i = 1; i <= n; ++i)

			cin >> a[i];

		if (n % 2 == 1)

		{

			cout << a[n];

			for (int i = n - 2; i >= 1; i = i - 2)

				cout << " " << a[i];

			for (int i = 2; i <= n - 1; i = i + 2)

				cout << " " << a[i];

			cout << endl;

		}

		else

		{

			cout << a[n];

			for (int i = n - 2; i >= 2; i = i - 2)

				cout << " " << a[i];

			for (int i = 1; i <= n - 1; i = i + 2)

				cout << " " << a[i];

			cout << endl;

		}

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int a[200005];

int main()

{

    int n;

    while(~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

            scanf("%d",&a[i]);

        if(n==1) printf("%d\n",a[0]);

        else if(n==2) printf("%d %d\n",a[1],a[0]);

        else

        {

            printf("%d",a[n-1]);

            for(int i=n-3; i>=0; i-=2)

                printf(" %d",a[i]);

            if(n%2==1)

                for(int i=1; i<n-1; i+=2)

                    printf(" %d",a[i]);

            if(n%2==0)

                for(int i=0; i<n-1; i+=2)

                    printf(" %d",a[i]);

            printf("\n");

        }

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



deque<int> a(200000,0);

deque<int> b;



int main(void)

{

    int n;

    cin >> n;



    for( int i = 0; i < n; i++){

        cin >> a[i];

    }



    for( int i = 0; i < n; i++){

        if( (n-1) % 2 == i % 2 ){

            b.push_front(a[i]);

        }else{

            b.push_back(a[i]);

        }

    }

    for( int i = 0; i < n; i++){

        cout << b[i] << " ";

    }



    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main(void)

{

    int N;

    cin >> N;

    int a[N];

    for( int i = 0; i < N; i++){

        cin >> a[i];

    }

    deque<int> A;

    for( int i = 0; i < N; i++){

        if( (i+N-1) % 2 == 0){

            A.push_front(a[i]);

        }else {

            A.push_back(a[i]);

        }

    }

    for( int i = 0; i < N; i++){

        cout << A[i] << " ";

    }

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



struct Bit

{

    int data[100005];



    Bit ()

    {

        fill(begin(data), end(data), 0);

    }



    void add ( int k, int x )

    {

        for ( k++; k < 100005; k += (k & -k) ) {

            data[k] += x;

        }

    }



    int sum ( int k )

    {

        int sum = 0;

        for ( k++; k > 0; k -= (k & -k) ) {

            sum += data[k];

        }

        return ( sum );

    }

};



int main()

{

    int N, M;

    int cnt = 0;

    Bit tree;

    pair < int , int > data[100005];



    cin >> N >> M;

    for ( int i = 0; i < M; i++ ) {

        cin >> data[i].second >> data[i].first;

    }

    sort(data, data + M);



    for ( int i = 0; i < M; i++ ) {

        if ( tree.sum(data[i].first) - tree.sum(data[i].second - 1) == 0 ) {

            tree.add(data[i].first - 1, 1);

            cnt++;

        }

    }

    cout << cnt << endl;

    return ( 0 );

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main()

{

    int N, M;

    int cnt = 0;

    pair < int , int > data[100005];



    cin >> N >> M;

    for ( int i = 0; i < M; i++ ) {

        cin >> data[i].second >> data[i].first;

    }

    sort(data, data + M);



    int ma = -1;

    for ( int i = 0; i < M; i++ ) {

        if ( ma <= data[i].second ) {

            ma = data[i].first;

            cnt++;

        }

    }

    cout << cnt << endl;

    return ( 0 );

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

typedef long long ll;

using namespace std;

const int MOD = 1000000007;

const int INF = 1010000000;

const double EPS = 1e-10;

const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



int main(){

  int n,m;cin>>n>>m;

  pair<int,int> d[100000];

  rep(i,m){

    int a,b;cin>>a>>b;

    d[i] = make_pair(a,b);

  }

  sort(d,d+m);

  int ans = 0;

  int pre_tail = 0;

  rep(i,m){

    if(d[i].first >= pre_tail){

      ans++;

      pre_tail = d[i].second;

    }else if(d[i].second < pre_tail)pre_tail = d[i].second;

  }

  cout << ans << endl;

}




// Optimized solution to the same problem (faster):
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

typedef long long ll;

typedef long double lb;

#define int long long

#define double long double

#define endn "\n"

typedef pair<int,int> P;

template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}

template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}

const int MOD = 1000000007;

//const int MOD = 998244353;

template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};

template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};

const ll INF = 1e16;

const double EPS = 1e-10;

const double PI = 3.141592653589793;

const string abc="abcdefghijklmnopqrstuvwxyz";

const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



////////////////////////////////////////////////////////////////////

///////////////////////___modpow___////////////////////

ll modpow(ll a,  ll n, const ll &MOD = MOD){

  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);

  (ret *= ret) %= MOD;

  if(n%2)((ret *= a) %= MOD);

  return ret;

}

///////////////////////___modinv___////////////////////

ll modinv(ll d, const ll &MOD = MOD){

  return modpow(d, MOD-2, MOD);

}

////////////////////////////////////////////////////////////////////



int n,m,ans;P p[110000];

signed main(){

  cin>>n>>m;

  rep(i,m)cin>>p[i].second>>p[i].first;

  sort(p, p+m);

  int t = -1;

  rep(i,m){

    if(t < p[i].second){

      t = p[i].first-1;

      ans++;

    }

  }

  cout << ans << endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



int N, M;

vector<pair<int, int>> P(100010);

bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }



int main(void){

    

    cin >> N >> M;

    for(int i = 0; i < M; ++i) cin >> P[i].first >> P[i].second;

    sort(P.begin(), P.begin() + M, compare);

    

    int ans = 0, end = 0;

    for(int i = 0; i < M; ++i){

        if(P[i].first >= end){

            end = P[i].second;

            ++ans;

        }

    }

    cout << ans << endl;

    

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

typedef tuple<int, int, int> T;



int N, M;

vector<P> ab;



int main(void){

    

    scanf("%d %d", &N, &M);

    for(int i = 0; i < M; ++i){

        int a, b; scanf("%d %d", &a, &b);

        ab.push_back(make_pair(b, a));

    }

    sort(ab.begin(), ab.end());

    

    int ans = 0, t = 0;

    for(int i = 0; i < ab.size(); ++i){

        if(t <= ab[i].second){

            t = ab[i].first;

            ++ans;

        }

    }

    printf("%d\n", ans);

    

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define mod 1000000007





int main(){

   int n,m;



   pair<int,int> data[100005];

   cin>>n>>m;

   for(int i=0;i<m;i++){

       int a,b;

       cin>>a>>b;

       data[i]=make_pair(b,a);

   }

   sort(data,data+m);

   int before=-1;

   int ans=0;

   for(int i=0;i<m;i++){

       if(before>=data[i].second) continue;

       ans++;

       before=data[i].first-1;

   }

   cout<<ans<<endl;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MOD 1000000007

#define INF 1e9

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main(void){

    int N,M;

    vector<pair<int,int>> A;

    cin>>N>>M;

    A.resize(M);

    for(int i=0;i<M;i++) cin>>A[i].second>>A[i].first;

    sort(A.begin(),A.end());

    int res=0;

    int endtime=0;

    for(int i=0;i<M;i++){

        if(A[i].second>=endtime){

            endtime=A[i].first;

            res++;

        }

    }

    cout<<res<<endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <string>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <iostream>

#include <algorithm>

using namespace std;

typedef long long ll;

const int Inf = 1 << 30;

const int maxx = 1e5 + 7;

int n, m;

int ans;



struct PP {

	int a, b;

} p[maxx];



bool Cmp(PP x, PP y) { return x.b < y.b; }



int main() {

	scanf("%d %d", &n, &m);

	for(int i = 1; i <= m; i++) scanf("%d %d", &p[i].a, &p[i].b);

	sort(p + 1, p + m + 1, Cmp);

	int t = 0;

	for(int i = 1; i <= m; i++) {

		if(p[i].a >= t){

			t = p[i].b; ans++;

		}

	}

	printf("%d\n", ans);

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <algorithm>

using namespace std;

const int maxx = 1e5 + 7;

int n, m, ans;



struct PP {

	int a, b;

} p[maxx];



bool Cmp(PP x, PP y) { return x.b < y.b; }



int main() {

	scanf("%d %d", &n, &m);

	for(int i = 1; i <= m; i++) scanf("%d %d", &p[i].a, &p[i].b);

	sort(p + 1, p + m + 1, Cmp);

	int t = 0;

	for(int i = 1; i <= m; i++) {

		if(p[i].a >= t){

			t = p[i].b; ans++;

		}

	}

	printf("%d\n", ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <algorithm>

#include <deque>



using namespace std;



struct war

{

    int a;

    int b;

};



bool cmp(const war& left, const war& right) {

    return left.b < right.b;

}



int main () {

    int N,M,a,b,sum=0;

    scanf("%d %d",&N,&M);

    war w;

    deque<war> wars;

    for (int i=0; i<M; i++) {

        scanf("%d %d",&a,&b);

        wars.push_back(war{a,b});

    }

    sort(wars.begin(),wars.begin()+M,cmp);

    while (wars.size() != 0) {

        w = wars.front(); wars.pop_front();

        for (size_t i=0; i<wars.size(); i++) {

            if(wars[i].a <= w.b-1) {

                wars.erase(wars.begin()+(int)i);

                i--;

            }

        }

        sum++;

    }

    printf("%d\n",sum);

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>



using namespace std;



struct war

{

    int a;

    int b;

};



bool cmp(const war& left, const war& right) {

    return left.b < right.b;

}



int main () {

    int N,M,a,b,sum=0,bridge=-1,i;

    scanf("%d %d",&N,&M);

    war wars[M];

    for (i=0; i<M; i++) {

        scanf("%d %d",&a,&b);

        wars[i] = war{a,b};

    }

    sort(wars,wars+M,cmp);

    for (i=0; i<M; i++) {

        if (wars[i].a > bridge) {

            bridge = wars[i].b-1;

            sum++;

        }

    }

    printf("%d\n",sum);

    return 0;

}

// Fastest known solution for this problem: