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
//package DP;
import java.util.*;
import java.io.*;
public class C
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;//static int n;
	static final long INF=(long)1e18;static int n;
	static int dp[]=new int[(int)5e5+7];
	static Pair arr[]=new Pair[dp.length];
	public static void main(String[] args) throws IOException
	{
		FastScanner fs=new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		n=fs.nextInt();Arrays.fill(dp,-1);
		for(int i=1;i<=n;i++)arr[i]=new Pair(fs.nextInt(),fs.nextInt());
		arr=sort(arr);
		//for(int i=1;i<=n;i++)out.println(arr[i].first+" "+arr[i].second);
		out.println(solve(1));
		out.close();
	}
	public static Pair[] sort(Pair arr[])
	{
		ArrayList<Pair> list = new ArrayList<Pair>();
		for(int i=1;i<=n;i++)list.add(new Pair(arr[i].first,arr[i].second));
		Collections.sort(list,new comp());
		for(int i=0;i<list.size();i++) {arr[i+1].first=list.get(i).first;arr[i+1].second=list.get(i).second;}
		return arr;
	}
	static class comp implements Comparator<Pair>
	{
		public int compare(Pair o1, Pair o2) {
			if(o1.first==o2.first)return 0;
			else if(o1.first>o2.first)return 1;
			else return -1;
		}
		
	}
	public static int solve(int ind)
	{
		if(ind==-1)return 0;
		if(ind>n)return 0;
		if(dp[ind]!=-1)return dp[ind];
		int ans=0;
		//System.out.println(ind);
		int idx=bin_search(arr,arr[ind].second+1);
		ans=Math.max(1+solve(idx),solve(ind+1));
	//	System.out.println(ans+" "+ind);
		return dp[ind]=ans;
	}
	public static int bin_search(Pair arr[],int key)
	{
		int left=1,right=n;int ans=-1;
		while(left<=right)
		{
			int mid=(left+right)/2;
			if(arr[mid].first>=key) {ans=mid;right=mid-1;}
			else left=mid+1;
		}
		return ans;
	}
	static class Pair
	{
		int first,second;
		Pair(int first,int second)
		{
			this.first=first;this.second=second;
		}
	}
	//returns the index of the smallest element in the array that is greater than or equal to
	//the given element.
	public static int lower_bound(int arr[],int key)
	{
		int index=inf,num=0;
		int left=0,right=arr.length-1;
		while(left<=right)
		{
			int mid=left+(right-left)/2;
			if(arr[mid]>=key) {index=mid;num=arr[mid];right=mid-1;}
			else 
				left=mid+1;
		}
		return index==inf ? arr.length:index;
	}
	//returns the index of the smallest element in the array that is less than or equal to
    //the given element.
	public static int upper_bound(int arr[],int key)
	{
		int index=inf,num=0;
		int left=0,right=arr.length-1;
		while(left<=right)
		{
			int mid=left+(right-left)/2;
			if(arr[mid]<=key) {index=mid;num=arr[mid];left=mid+1;}
			else 
				right=mid-1;
		}
		return index==inf ? arr.length:index;
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		public String nextLine() throws IOException
		{
		    return br.readLine();
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}
