#BS0000063. Búp bê lồng nhau (Nested Dolls)

Búp bê lồng nhau (Nested Dolls)

Nested Dolls

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Doll (w1,h1)(w_1,h_1) fits inside (w2,h2)(w_2,h_2) iff w1<w2w_1<w_2 and h1<h2h_1<h_2. Partition all dolls into the minimum number of nesting chains.

Input

The first line contains mm. The second line contains w1,h1,…,wm,hmw_1,h_1,\ldots,w_m,h_m.

Output

Print the minimum number of chains.

Subtasks

  • Subtask 1 — 20%: m≤100m\le100.
  • Subtask 2 — 30%: m≤5000m\le5000.
  • Subtask 3 — 50%: m≤20000m\le20000, 1≤wi,hi≤100001\le w_i,h_i\le10000.

Example

Input

4
20 30 10 10 30 20 40 50

Output

2

Explanation

Two nesting chains are sufficient and one is impossible.