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.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class a {
	public static class node implements Comparable<node> {
		int x;
		int y;

		node(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(node o) {
			if (o.y < y)
				return 1;
			else if (o.y > y)
				return -1;
			else if (o.x < x)
				return 1;
			else if (o.x > x)
				return -1;
			return 0;
		}

	}

	public static class point {
		int x;
		int y;

		point(int x, int val) {
			this.x = x;
			this.y = val;
		}

	}

	public static BigInteger gcd(BigInteger a, BigInteger b) {
		if (b.equals(BigInteger.ZERO))
			return a;
		return gcd(b, a.mod(b));
	}

	public static long gcd1(long a, long b) {
		if (b == 0)
			return a;
		return gcd1(b, a % b);
	}

	public static ArrayList<Integer> prime;

	public static void sieve(int n) {
		boolean vis[] = new boolean[n + 5];
		vis[1] = true;
		vis[0] = true;
		for (int i = 2; i <= n; i++) {
			if (!vis[i]) {
				prime.add(i);
				for (long j = (long) i * (long) i; j <= n; j += i) {
					vis[(int) j] = true;
				}
			}
		}
	}

	public static int tree[][];
	public static boolean end[][];
	public static int counter;

	public static void trie(String a) {
		int st = 0;

		for (int i = 0; i < a.length(); i++) {
			if (tree[a.charAt(i) - 'a'][st] == 0) {
				tree[a.charAt(i) - 'a'][st] = counter++;
			}

			st = tree[a.charAt(i) - 'a'][st];
		}
		end[a.charAt(a.length() - 1) - 'a'][st] = true;

	}

	public static int seg[][];

	public static int get(int s, int e, int p, int from, int to, int seg[]) {
		if (s >= from && e <= to)
			return seg[p];
		if (s > to || e < from)
			return 0;
		int mid = (s + e) / 2;
		int one = get(s, mid, p * 2, from, to, seg);
		int two = get(mid + 1, e, p * 2 + 1, from, to, seg);
		return Math.max(one, two);
	}

	public static long comp(int n, int r) {
		long ans = 1;
		r = Math.min(r, n - r);
		for (int i = 1; i <= r; i++) {
			ans = ans * ((long) n - (long) i + 1L) / (long) i;
		}
		return ans;
	}

	public static ArrayList<Integer> arr[];
	public static boolean vis[];
	public static Stack<Integer> S;

	public static void bfs(int node) {
		for (int i = 0; i < arr[node].size(); i++) {
			int k = arr[node].get(i);
			if (vis[k] == false) {
				vis[k] = true;
				S.push(k);
				bfs(k);
			}
		}
		S.push(node);
	}

	public static void dfs(int node) {

		for (int i = 0; i < arr[node].size(); i++) {
			int k = arr[node].get(i);
			if (vis[k] == false) {
				vis[k] = true;
				dfs(k);
			}
		}
	}

	public static boolean chPrime(int r) {

		for (int i = 2; i * i <= r; i++) {
			if (r % i == 0)
				return false;
		}
		return true;
	}

	public static int len(long ai) {
		String temp = "" + ai;

		return temp.length();
	}

	public static int f_digit(long ai) {
		String temp = "" + ai;

		return (temp.charAt(0) - '0');

	}

	public static HashMap<Long, Long> dp[];
	public static int block;

	public static long solve(int k, long num, long ai, int bi) {
		if (k == block) {
			if (num == 0) {
				return 1;
			}

			return 0;
		}

		if (dp[k].containsKey(num))
			return dp[k].get(num);

		long a = 0;
		long b;
		for (int i = 0; i < 10; i++) {
			if (k == 0 && i == bi)
				continue;

			b = num + ((long) Math.pow(10, block - k - 1) * (long) i);
			b %= ai;

			a += solve(k + 1, b, ai, bi);
		}
		dp[k].put(num, a);
		return a;
	}

	public static long mo = (long) Math.pow(10, 9) + 7;

	public static long solve(long ai, int len, int bi) {

		long ans = 0;
		HashSet<Long> mp = new HashSet();
		Queue<Long> q = new LinkedList();
		q.add(ai);
		mp.add(ai);

		while (!q.isEmpty()) {

			long e = q.poll();

			int len2 = len(e);

			if (len2 < len) {
				if (bi != 0)
					ans++;
			} else if (len2 == len) {
				if (f_digit(e) != bi)
					ans++;
			}

			for (int i = 0; i < prime.size(); i++) {
				long d = e * (long) prime.get(i);
				if (len(d) > len)
					break;

				if (!mp.contains(d)) {
					mp.add(d);
					q.add(d);
				}
			}

		}

		return ans;
	}

	public static long mod = (long) Math.pow(10, 9) + 7;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader in = new BufferedReader(new FileReader("cubes.in"));
		// System.out.println(-70 % 3);
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		int n = Integer.parseInt(in.readLine());
		PriorityQueue<node> q = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
			String y[] = in.readLine().split(" ");
			int l = Integer.parseInt(y[0]);
			int r = Integer.parseInt(y[1]);
			q.add(new node(l, r));
		}
		node e = q.poll();
		int ans = 1;
		
		int r = e.y;
		while (!q.isEmpty()) {

			e = q.poll();

			if (e.x > r) {
				ans++;
				r = e.y;
			}

		}
		System.out.println(ans);
		// System.out.println(n+" "+m);

		out.close();

	}
}