A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Output

Print the maximal number of orders that can be accepted.

Examples

Input

2
7 11
4 7


Output

1


Input

5
1 2
2 3
3 4
4 5
5 6


Output

3


Input

6
4 8
1 5
4 7
2 5
1 3
6 8


Output

2
import java.util.*;
import java.io.*;

public class Main {
	public static Scanner in = new Scanner(System.in);
	static void swap(int []a,int i,int j) {
		int t = a[i];
		a[i]=a[j];
		a[j]=t;
	}
	static void select(int []a,int k) {
		int x = a[0];
		for(int i=1;i<a.length;i++) {
			if(a[i]<=x) {
				swap(a,i,x);
				x=i;
			}
		}
		
	}
	static int solve(int n,int v,int k,boolean vis[][],int dp[][]) {
		
		//System.out.println(n+" "+v+" "+k);
		if(n<0) return 0;
		if(k==0 && n>0) return 0;
		if(n==0 && k==0) {
			vis[0][0]=true;
			return dp[n][k]=1;
		}
		if(vis[n][k]) return dp[n][k];
		vis[n][k]=true;
		for(int i=v;i>=1;i--)
			dp[n][k]+=(solve(n-i,i,k-1,vis,dp))%1988;
		return dp[n][k];
	}
    public static void main(String[] args) {
    	int n = in.nextInt();
    	Interval a[]=new Interval[n];
    	for(int i=0;i<n;i++) {
    		a[i]=new Interval(in.nextInt(),in.nextInt());
    	}
		Arrays.sort(a,new Comparator<Interval>() {
			@Override
			public int compare(Interval o1, Interval o2) {
				return o1.s-o2.s;
			}
		});
		TreeMap<Interval,Integer> m = new TreeMap<Interval,Integer>(new Comparator<Interval>() {
			@Override
			public int compare(Interval o1, Interval o2) {
				return o1.f-o2.f;
			}
		});
		m.put(a[0],1);
		int ans=0,f=1;
		for(int i=1;i<n;i++) {
			while(!m.isEmpty() && m.firstKey().f<a[i].s) {
				ans=Math.max(ans, m.firstEntry().getValue());
				m.remove(m.firstKey());
			}
			m.put(a[i], ans+1);
			f = Math.max(ans+1,f);
		}
		System.out.println(f);
    	//System.out.println(solve(7,7,3,new boolean[5001][5001],new int[5001][5001]));
    	/*int n = in.nextInt(),m=in.nextInt();
    	int dp[][]=new int[n+1][n+1];
    	dp[0][0]=1;
    	//for(int i=1;i<=n;i++) {
				for(int j=1;j<=n;j++) {
					for(int k=0;k<=n;k++) {
					if(j-k>=0)
						dp[j][k]+=dp[j-k][k];
					dp[j][k]+=dp[j-1][k];
					dp[j][k]%=1988;
				}
			}
    	//}
    	//dp[m]=sum of all such dp[i]
    	System.out.println(dp[n][m]);
    	/*long a[]=new long[n];
    	long dp[][][]=new long[n][n][2];
    	long max[][][]=new long[n][n][2];
    	long sum[][]=new long[n][n];

    	for(int i=0;i<n;i++) a[i]=in.nextInt();
    	for(int i=0;i<n;i++) {
    		sum[i][i]=a[i];
    		for(int j=i-1;j>=0;j--) {
    			sum[i][j]=sum[i][j+1]+a[j];
    		}
    	}
    	dp[0][1][0]=a[0];
    	//dp[1][2][0]=a[0]+a[1];
    	for(int j=n-2;j>=0;j--) {
			max[0][j][0]=Math.max(max[0][j+1][0],dp[0][j][0]);
			max[0][j][1]=Math.max(max[0][j+1][1],dp[0][j][1]);
			max[1][j][0]=Math.max(max[1][j+1][0],dp[1][j][0]);
			max[1][j][1]=Math.max(max[1][j+1][1],dp[1][j][1]);
		}

    	for(int i=1;i<n;i++) {
    		for(int j=1;j<=i;j++) {
    			if(i-j>=0) {
    				dp[i][j][0]=Math.max(dp[i][j][0],max[i-j][(j+1)/2][1]+sum[i][i-j+1]);
    				dp[i][j][1]=Math.max(dp[i][j][1],max[i-j][(j+1)/2][0]);
    			}
    		}
    		max[i][n-1][0]=dp[i][n-1][0];
    		max[i][n-1][1]=dp[i][n-1][1];
    		for(int j=n-2;j>=0;j--) {
    			max[i][j][0]=Math.max(max[i][j+1][0],dp[i][j][0]);
    			max[i][j][1]=Math.max(max[i][j+1][1],dp[i][j][1]);
    		}
    	}
    	long ans=0;
    	for(int i=0;i<n;i++) {
    		ans=Math.max(dp[n-1][i][0],ans);
    	}
    	System.out.println(ans);*/
    }
    static public long read(long []t,int i) {
    	long sum=0;
    	while(i>0) {
    		sum+=t[i];
    		i-=(i&-i);
    	}
    	return sum;
    }
    static public void upd(long []t,int i) {
    	while(i<1000002) {
    		t[i]++;
    		i+=(i&-i);
    	}
    }
   /* public static Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
    	int n = in.nextInt(),m=in.nextInt();
    	HashSet<String> h = new HashSet<String>();
    	for(int i=0;i<n;i++) {
    		h.add(in.next());
    	}
    	int cn=0;
    	for(int j=0;j<m;j++) {
    		if(h.contains(in.next())) cn++;
    	}
    	n-=cn;
    	m-=cn;
    	if(m-n<(cn%2)) System.out.println("YES");
    	else System.out.println("NO");
     }
    /*
    public static void main(String[] args) {
       int n = in.nextInt();
       Segments s[] = new Segments[n];
       ArrayList<Long> xcord = new ArrayList<Long>();
       for(int i=0;i<n;i++) {
    	   long x,y;
    	   s[i]=new Segments(x=in.nextLong(),y=in.nextLong());
    	   in.nextInt();
    	   xcord.add(2*x);
    	   xcord.add(2*y);
       }
       Collections.sort(xcord);
       ArrayList<Long> nxcord = new ArrayList<Long>();
       for(int i=0;i<xcord.size()-1;i++) {
    	   nxcord.add((xcord.get(i)+xcord.get(i+1))/2);
       }
       xcord.addAll(nxcord);
       Collections.sort(xcord);
       
       for(int i=0;i<xcord.size();i++) {
    	   int j=i+1;
    	   long p = xcord.get(i);
    	   while(j<n && xcord.get(j)==xcord.get(i)) j++;
    	   int cn=0;
    	   for(int k=0;k<n;k++) {
    		   if(s[i].s<p && s[i].f>p) cn++;
    	   }
    	   for(int k=i-1;k>=0;k--) {
    		   
    	   }
       }
    }*/
    
}
class Segments{
	long s,f;
	Segments(long s,long f){
		this.s = s;
		this.f = f;
	}
}
/*
class dir{
	boolean l,r,u,d;
}
class Node extends ArrayList<Node>{

	private static final long serialVersionUID = 1L;
	double x,y;
	int i;
	boolean visited=false;
	Node(int x,int y,int i){
		this.x = x;
		this.y = y;
		this.i=i;
	}
	void reset(){
		visited = false;
	}
	boolean dfs(dir d,double mid,double w,double h,double [][]dists,double cmpr){
		visited = true;
		if(x+mid>=w)
			d.r=true;
		if(x-mid<=0.0)
			d.l=true;
		if(y+mid>=h)
			d.u=true;
		if(y-mid<=0.0)
			d.d=true;
		if((d.l && d.d) || (d.u && d.r) 
				|| (d.l && d.r) || (d.u && d.d)) {
			return true;
		}
		for(Node n : this) {
			if(!n.visited) {
				boolean fl=false;
				if(dists[i][n.i]<=cmpr)
					fl|=n.dfs(d,mid,w,h,dists,cmpr);
				if(fl) return fl;
			}
		}
		return false;
	}
	double dist(Node n1,Node n2) {
		return sq(n1.x-n2.x)+sq(n1.y-n2.y);
	}
	double sq(double a) {
		return a*a;
	}
}
class ChristmasBinaryTree{
    public int count(long d, int[] left, int[] right) {
    	int n = left.length;
    	int dp[][][]=new int[120][120][64];
    	for(int i=0;i<n;i++) {
    		dp[i][left[i]][0]=1;
    		dp[i][right[i]][0]=1;
    	}
    	while(d>0) {
    		long k=0;
    		for(;1<<k<=d;k++) {
    			for(int i=0;i<n;i++) {
    				for(int j=0;j<n;j++) {
    					for(int l=0;l<n;l++) {
    						dp[i][l][(int)k+1]+=
    								dp[i][j][(int)k]*dp[j][l][(int)k];
    						
    					}
    				}
    			}
    		}
        	int ndp[][][]=new int[120][120][64];
    		for(int i=0;i<n;i++) {
    			for(int j=0;j<n;j++) {
    				ndp[i][j][0]=dp[i][j][(int)k];
    			}
    		}
    		dp=ndp;
    		d-=1<<(k-1);
    	}
    	int cn=0;
    	for(int i=0;i<n;i++) {
    		for(int j=0;j<n;j++) {
    			cn+=dp[i][j][0]*dp[i][j][0];
    		}
    	}
    	return cn;
    }
}
/*
public class Main {
	private static InputReader in = new InputReader(System.in);
	public static void main(String args[]) {
		StringBuilder s = new StringBuilder();
		int t = in.readInt();
		while(t>0) {
			
			t--;
		}
		System.out.println(s);
	}

	/*public static int solve(String s, int i,int j,
    		int dp[][],boolean visited[][]) {
    	if(i>j) return 0;
    	if(i==j) return dp[i][j]=1;
    	if(visited[i][j]) return dp[i][j];
    	visited[i][j]=true;
    	solve(s,i+1,j,dp,visited);
    	solve(s,i,j-1,dp,visited);
    	if(s.charAt(i)==s.charAt(j)) {
    		if(i+1==j)
    			return dp[i][j]=2;
    		else {
    			return dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+1;
    		}
    	}else {
    		if(i+1==j) return dp[i][j]=1;
    		return dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1];
    	}
    }*/
	/*
    public static void main(String args[]) {
    	int t = in.nextInt();
    	while(t>0) {
    		int m = in.nextInt(), n = in.nextInt();
    		long p = in.nextLong();
    		long dp[][][]=new long[11][300][300];

    		for(int i=1;i<=m;i++)
    			dp[1][i][i]=1;
    		for(int i=1;i<n;i++) {
    			for(int j=1;j<m;j++) {
    				for(int k=1;k<=j;k++) {
    					for(int l=k;l>=1;l--) {
    						if(j+l<=m)
    							dp[i+1][j+l][l]+=dp[i][j][k];
    					}
    				}
    			}
    		}
    		System.out.println(dp[n][m-1][2]);
    		for(int i=n;i>0;i--) {
    			for(int j=1;j<=m;j++) {
    				if(dp[i][m-j][j]>=p) {
    					//System.out.print(j+" ");
    					m-=j;
    					break;
    				}else {
    					p-=dp[i][m-j][j];
    					System.out.print(p+" ");
    				}
    			}
    		}
    		System.out.println();
    		t--;
    	}

    }*/

class sh implements Comparable<sh>{
	int h,w,i;
	sh(int a,int b,int c){
		w=a;
		h=b;
		i=c;
	}
	@Override
	public int compareTo(sh o) {
		if(w==o.w) return h-o.h;
		return w-o.w;
	}

}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public byte read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}
} 
class Interval{
	int s,f;
	Interval(int x,int y){
		s = x;
		f = y;
	}
}


