#t521. 珍珠
珍珠
Pearls
Problem Background
Special for beginners, ^_^
Problem Description
There are pearls that are identical in shape and size, but their weights are all different. is an integer, and all the pearls are numbered from to . Your task is to find out which pearl has exactly the middle weight, i.e. its weight ranks -th among all the pearls' weights. The following is a way to compare a pair of pearls:
You are given a balance to compare the weights of pearls; we can tell which of two pearls is heavier. After a series of comparisons, we can remove some pearls that definitely do not have the middle weight.
For example, the following shows four comparisons on pearls:
- Pearl is heavier than pearl ;
- Pearl is heavier than pearl ;
- Pearl is heavier than pearl ;
- Pearl is heavier than pearl .
From the above results, although we cannot precisely find which pearl has the middle weight, we can be sure that pearl and pearl cannot have the middle weight, because pearls are heavier than pearl , while pearls are lighter than pearl , so we can remove these two pearls.
Write a program to count how many pearls are definitely not of middle weight.
Input Format
The first line of input contains two integers separated by a space: and , where and is odd. is the number of comparisons made on the pearls. The following lines each contain two integers separated by a space: and , meaning pearl is heavier than pearl .
Output Format
Output a single line containing one integer: the total number of pearls that cannot be of middle weight.
Sample Input
123 500
Sample Output
623
Constraints
Time limit: 1s; memory limit: 1024 KiB for each test case.