Every day, Farmer John's $N$ cows ($1 \le N \le 100{,}000$) cross a road that runs through the middle of his farm. Viewing the map of the farm in the 2D plane, the road runs horizontally, with one side described by the line $y = 0$ and the other by the line $y = 1$. Cow $i$ crosses the road along a straight path from position $(a_i, 0)$ on one side to position $(b_i, 1)$ on the other side. All of the $a_i$ are distinct, as are all of the $b_i$, and all of these numbers are integers in the range $-1{,}000{,}000$ to $1{,}000{,}000$.
Despite the relative agility of his cows, Farmer John often worries that a pair of cows whose paths intersect might injure each other if they collide while crossing. He considers a cow to be "safe" if no other cow's path intersects her path. Please help him count the number of safe cows.
The paths of two cows $i$ and $j$ intersect exactly when their left-to-right order at the start is reversed at the end — that is, when $(a_i - a_j)$ and $(b_i - b_j)$ have opposite signs. Therefore cow $i$ is safe if and only if there is no other cow that starts to her left ($a_j < a_i$) yet ends to her right ($b_j > b_i$), and no cow that starts to her right yet ends to her left.
For example, suppose there are 4 cows and cow 1 crosses from $(-3, 0)$ to $(4, 1)$. Then cows 1 and 3 do not intersect any other cow and are safe, while cows 2 and 4 intersect each other and are not safe.