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.StringTokenizer;
import java.util.Collections;
import java.util.Collection;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Queue;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Stack;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Iterator;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileReader;

import java.math.BigInteger;

public class Main extends Exception
{
	static PrintWriter writer;
	static StringTokenizer sz;
	static BufferedReader reader;

	public static void main(String[] args)
	throws Exception
	{
		declare();

		int n = readInt();
		ArrayList<Pair> vals = new ArrayList<Pair>();
		for (int i=0;i < n;++i)
		{
			readLine();
			vals.add(new Pair(readInt(), readInt()));
		}

		Collections.sort(vals);
		Pair temp = vals.get(0);
		int res = 1;
		int f = temp.first;
		int s = temp.second;

		for (int i=1;i < n;++i)
		{
			temp = vals.get(i);

			if (temp.first > f && temp.second < s)
			{
				f = temp.first;
				s = temp.second;
			}
			else
			if (temp.first > s)
			{
				++res;
				f = temp.first;
				s = temp.second;
			}
		}

		writer.print(res);
		close();
	}

	private static class Pair implements Comparable<Pair>
	{
		int first,second;

		public Pair(int f, int s)
		{
			first = f;
			second = s;
		}

		public Pair(Pair p)
		{
			first = p.first;
			second = p.second;
		}

		@Override
		public int compareTo(Main.Pair p1)
		{

			if (first == p1.first)
				return  second - p1.second;
			return first - p1.first;

		}

		@Override
		public String toString()
		{
			return first + " " + second + "\n";
		}
	}

	private static String readString()
	throws IOException
	{
		if (sz.hasMoreTokens())
			return sz.nextToken();
		return reader.readLine();
	}

	private static void readLine()
	throws IOException
	{
		sz = new StringTokenizer(reader.readLine());
	}

	private static int readInt()
	throws IOException
	{
		if (sz.hasMoreTokens())
			return Integer.parseInt(sz.nextToken());
		return Integer.parseInt(reader.readLine());
	}

	private static long readLong()
	throws IOException
	{
		if (sz.hasMoreTokens())
			return Long.parseLong(sz.nextToken());
		return Long.parseLong(reader.readLine());
	}

	private static void declare()
	{
		writer = new PrintWriter(System.out);
		reader = new BufferedReader(
			new InputStreamReader(System.in));
		sz = new StringTokenizer("");
	}

	private static void declareFile()
	throws IOException
	{
		writer = new PrintWriter("output.txt");
		reader = new BufferedReader(
			new FileReader("input.txt"));
		sz = new StringTokenizer("");
	}

	private static void close()
	throws IOException
	{
		reader.close();
		writer.flush();
		writer.close();
	}
}

  




  


