def burger(i)
  if i == 0
    'P'
  else
    'B' + burger(i-1) + 'P' + burger(i-1) + 'B'
  end
end

def burger_num(level, x)
  return 1 if level == 0
  if @hb.has_key?(level)
    return @hb[level][0..x-1].count('P')
  end

  prev_level_size = @h[level-1]
  if x == 0
    0
  elsif x == prev_level_size + 2
    burger_num(level-1, prev_level_size) + 1
  elsif x == @h[level]
    burger_num(level-1, prev_level_size) * 2 + 1
  elsif x < prev_level_size + 2
    burger_num(level-1, x-1)
  else
    burger_num(level-1, prev_level_size) + 1 + burger_num(level-1, x-2-prev_level_size)
  end
end

n, x = gets.split.map(&:to_i)
q = 1
@h = {0=>q}
@hb = {0=>'P'}
(1..n).each do |i|
  q = 3 + q*2
  @h[i] = q
  @hb[i] = burger(i) if i < 15
end

puts burger_num(n, x)