Fixing the Tournament
InterviewTime limit1sMemory limit1024 MB
Given n and your team's rank r in a bracket of 2^n single-elimination teams, find the latest round your team can reach when you choose every pairing.
Problem
The most common tournament format is a single elimination tournament played in rounds. To run one, the number of teams at the start must be a power of 2. For example, a tournament that starts with 16 () teams has 8 matches in round 1, which leaves 8 winners and 8 losers. In round 2, the 8 winners are paired into 4 matches. The winners keep being paired this way until two teams remain for the final match.
In this problem, assume that:
- the teams are ranked from 1 to for a positive integer n
- the best team is ranked 1 and the worst team is ranked (this is called "one-based ranking")
- whenever a team with a better rank (lower number) plays a team with a worse rank, the better-ranked team wins.
The pairings are not fixed. You have hacked into the tournament software, so you can pair the remaining teams in any way you want in each round. Find the highest round your favorite team can reach.
Input
A single line contains two integers: n (), the number of rounds in the tournament, and r (), your team's one-based ranking.
Output
Print the highest round number your team could reach, on a line by itself.