N,X = `dd`.split.map(&:to_i)
$ss = [1]
N.times{ $ss << $ss[-1]*2+3 }
$ps = [1]
N.times{ $ps << $ps[-1]*2+1 }

def dig(n,x)
  ans = case
  when n == 0; 1
  when x == 1; 0
  when x <= 1+$ss[n-1]; dig(n-1,x-1)
  when x == 1+$ss[n-1]+1; $ps[n-1]+1
  when x < $ss[n]; $ps[n-1]+1+dig(n-1,x-1-$ss[n-1]-1)
  when x == $ss[n]; $ps[n]
  end
  #p [n,x,$ss[n],$ps[n],ans]
  ans
end

p dig(N,X)