function Main(input) {
	var inputArr = input.split("\n");
	var knArr = inputArr[0].split(" ");
	var n = parseInt(knArr[0], 10);
	var x = parseInt(knArr[1], 10);
  
    var bg = "P";
	for(var i = 1; i <= n; i++) {
      bg = burger(bg);
      if (bg.len > x) {
        break;
      }
	}
    console.log(bg.substr(bg.length-x,x).replace(/B/g, '').length);
}
function burger(val) {
  return "B" + val + "P" + val + "B";
};
Main(require("fs").readFileSync("/dev/stdin", "utf8"));