#ARC147E. [ARC147E] Examination

[ARC147E] Examination

Score : 800800 points

Problem Statement

NN students, numbered 1,2,,N1,2,\ldots,N, took an examination. Student i(1iN)i\,(1 \leq i \leq N) had to score at least BiB_i points to graduate, where they actually scored AiA_i points.

You can repeat the following operation any number of times (possibly zero):

  • Choose two students, and swap their scores.

Your goal is to make everyone graduate. Determine whether it is possible. If it is possible, find the maximum number of students whose scores do not change during the process.

Constraints

  • 2N3×1052 \leq N \leq 3 \times 10^5
  • 1Ai,Bi109(1iN)1 \leq A_i,B_i \leq 10^9\,(1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

If it is possible to make everyone graduate, print the maximum number of students whose scores do not change during the process.

Otherwise, print -1.

3
1 2
3 1
3 3
1

If you swap scores of Student 11 and 22, everyone can graduate. Here, the number of students whose scores do not change is 11 (only Student 33).

2
100 1
100 1
2
6
3 2
1 6
4 5
1 3
5 5
9 8
-1
6
3 1
4 5
5 2
2 3
5 4
5 1
3