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

@burgers = [1]
@meats = [1]

n.times do |i|
  @burgers.push(@burgers.last*2 + 3)
  @meats.push(@meats.last*2+1)
end

def bite_meat(level, bites)
  return 0 if bites == 0
  return 1 if level == 0
  if bites >= @burgers[level-1]+2
    @meats[level-1] + 1 + bite_meat(level-1, bites-@burgers[level-1]-2)
  else
    bite_meat(level-1, bites-1)
  end
end

p bite_meat(n, x)
