pattys_of_level = 50.times.inject([1]){|acc, it| acc.push(acc.last * 2 + 1)}
height_of_level = 50.times.inject([1]){|acc, it| acc.push(acc.last * 2 + 3)}

define_method(:pattys_of_height_and_level){|lv, h|
    if h == 0 
        return 0
    end

    if h == height_of_level[lv]
        return pattys_of_level[lv]
    end

    mid_patty = height_of_level[lv - 1] + 2

    if h < mid_patty
        return pattys_of_height_and_level(lv - 1, h - 1)
    elsif h == mid_patty
        return pattys_of_level[lv - 1] + 1
    else
        return pattys_of_level[lv - 1] + 1 + pattys_of_height_and_level(lv - 1, h - mid_patty)
    end
}

n, x = gets.split.map(&:to_i)
puts pattys_of_height_and_level(n, x)

