def bg_len(n)
  if n == 0
    1
  else
    3 + bg_len(n - 1) * 2
  end
end

def bg_p(n)
  if n == 0
    1
  else
    1 + bg_p(n - 1) * 2
  end
end

def bg_ans(n, x)
  if x == 0
    0
  elsif x == 1
    n == 0 ? 1 : 0
  elsif n == 0
    1
  else
    x -= 1
    l = bg_len(n - 1)

    if x < l
      bg_ans(n - 1, x)
    elsif x == l
      bg_p(n - 1)
    elsif x == (l + 1)
      bg_p(n - 1) + 1
    else
      p = bg_p(n - 1) + 1
      p + bg_ans(n - 1, x - l - 2)
    end
  end
end

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

puts bg_ans(n, x)
