$a = {}
def all(n)
  return 1 if n == 0
  return $a[n] if $a[n]
  $a[n] = 3 + 2*all(n-1) 
end

$b = {}
def patall(n)
  return 1 if n == 0
  return $b[n] if $b[n]
  $b[n] = 1 + 2*patall(n-1)
end

def pat(n, x)
  return 0 if x <= 0
  return patall(n) if all(n) == x

  return pat(n-1,x-1) if 1+all(n-1) >= x

  r = 0
  r += patall(n-1)
  x -= 1+all(n-1)
  return r if x == 0
  r += 1
  x -= 1

  if all(n-1) <= x
    r += patall(n-1)
    return r
  else
    r += pat(n-1, x)
    return r
  end
end

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