1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 679 Dropping Balls
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=8&page=show_problem&problem=620
*
* @author Stefan Burgmair
* @author YYY
* @version 1.0, 26/04/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.084
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

reader.readLine();
do{
String[] inputLine = reader.readLine().split(" ");
int generalDepth = Integer.parseInt(inputLine[0]);
if (generalDepth > -1){
int numberOfBalls = Integer.parseInt(inputLine[1]);
System.out.println(letTheBallsRoll(1, generalDepth, numberOfBalls));
}
}while (reader.ready());
}

static int letTheBallsRoll(int numberOfNode, int generalDepth, int numberOfBalls){
if (generalDepth == 1)
return numberOfNode;
if (numberOfBalls % 2 == 0)
return letTheBallsRoll(numberOfNode * 2 + 1, generalDepth - 1, numberOfBalls/2);
else
return letTheBallsRoll(numberOfNode * 2, generalDepth - 1, (numberOfBalls+1)/2);
}
}