Ticket Triage Deadlines
The support team's queue has n open tickets. Ticket i can't be worked on before day s_i, because that's when the customer sends the logs it needs, and it's only worth resolving if it's done by day e_i, its SLA deadline. Once the deadline passes, the ticket is escalated and taken off the on-call engineer's plate.
The on-call engineer resolves at most one ticket per day, and each ticket takes exactly one day. Ticket i is resolved if the engineer works on it on some integer day d with s_i ≤ d ≤ e_i.
Work out a schedule that resolves as many tickets as possible, and print how many that is.
Input
The first line contains an integer n (1 ≤ n ≤ 10^5), the number of tickets.
Each of the next n lines contains two integers s_i and e_i (1 ≤ s_i ≤ e_i ≤ 10^9): the first and last day ticket i can be resolved, inclusive.
Output
Print one integer: the maximum number of tickets that can be resolved.
Notes
In the first example the five tickets all fall within days 1 to 4, so at most four can be resolved. Four is achievable: on day 1 resolve ticket 3 [1, 2], on day 2 ticket 2 [2, 2], on day 3 ticket 1 [1, 3], and on day 4 ticket 5 [4, 4].
In the second example only days 5 and 6 work for the three tickets [5, 5], [5, 5] and [5, 6], so one of them is left over. Each of the other three tickets gets its own day.