#Q1. 「一本通 1.1 例 1」活动安排

「一本通 1.1 例 1」活动安排

Description

Given a set of nn activities E={1,2,..,n}E=\{1,2,..,n\}, where each activity requires the use of a common resource, such as a lecture hall, and only one activity can use the resource at any given time. Each activity ii has a start time sis_i and an end time fif_i for using the resource, with si<fis_i < f_i. If activity ii is selected, it occupies the resource during the time interval [si,fi)[s_i, f_i). The intervals [si,fi)[s_i, f_i) and [sj,fj)[s_j, f_j) are said to be compatible if they do not overlap, i.e., when fisjf_i \leq s_j or fjsif_j \leq s_i. The task is to select the largest subset of mutually compatible activities.

Input Format

The first line contains an integer nn;

The next nn lines each contain two integers sis_i and fif_i.

Output Format

Output the maximum number of mutually compatible activities.

Sample 1

4
1 3
4 6
2 5
1 7

2

Constraints & Hints

1n10001 \leq n \leq 1000