func burger(L: Int) -> String {
    if L > 0 {
        let pre = burger(L-1)
        return "B" + pre + "P" + pre + "B"
    } else {
        return "P"
    }
}
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, X) = (input[0], input[1])
print(burger(N).characters.map{$0}[0..<X].reduce(0){$0+($1>"B" ?1:0)})