#P2652. 同花顺

同花顺

Description

Now I have nn playing cards, but they may not form a straight flush. I want to know the minimum number of cards I need to replace so that all nn cards form a straight flush.

Input Format

The first line contains an integer nn, indicating the number of playing cards.

Then nn lines follow, each containing two integers aia_{i} and bib_{i}. Here, aia_{i} denotes the suit of the ii-th card, and bib_{i} denotes the rank of the ii-th card.

Output Format

Output a single integer on one line, indicating the minimum number of cards that need to be replaced to achieve the goal.

5
1 1
1 2
1 3
1 4
1 5
0
5
1 9
1 10
2 11
2 12
2 13
2

Hint

  • For 30%30\% of the testdata, n10n \le 10.
  • For 60%60\% of the testdata, n105n \le 10^{5}, 1ai1051 \le a_{i} \le 10^{5}, 1bin1 \le b_{i} \le n.
  • For 100%100\% of the testdata, n105n \le 10^{5}, 1ai,bi1091 \le a_{i}, b_{i} \le 10^{9}.

Translated by ChatGPT 5