DBG = !true

# # of patties of k-level burger
def p(k)
  return (2**(k+1) - 1)
end

# # of layers of k-level burger
def s(k)
  return (2**(k+2) - 3)
end

def f(n,x)
  ret = -1 # dmy
  if n==0 || x == 0
    ret = x
  elsif x == 1  # n>0
    ret = 0
  elsif x == 2*s(n-1)+3
    ret = f(n, x-1)
  elsif x > s(n-1)+2
    ret = (p(n-1) + 1 + f(n-1, x-s(n-1)-2))
  elsif x == s(n-1)+2
    ret = (p(n-1) + 1)
  elsif x > 1
    ret = f(n-1, x-1)
  end

  printf("f(%d,%d) returns %d\n", n, x, ret) if DBG
  return ret
end

n,x = gets.split.map{|x| x.to_i}
printf("n:%d x:%d\n", n, x) if DBG
print f(n,x)
