output_description: Print the number of patties in the bottom-most X layers from the bottom of a
  level-N burger.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N X
attempt: def delete_head_zeros(n):
      n = str(n)
      l = len(n)
      if "." in n:
          l = n.find(".")
      head_zeros = 0
      for i in range(l - 1):
          if n[i] == "0":
              head_zeros += 1
          else:
              break
  
      return n[head_zeros:]
  
  
  # compare a, b
  # a, b: int or string
  def bigint_compare(a, b):
      a = delete_head_zeros(a)
      b = delete_head_zeros(b)
      if len(a) > len(b):
          return 1
      elif len(a) < len(b):
          return -1
      else:
          if a > b:
              return 1
          elif a < b:
              return -1
          else:
              return 0
  
  
  # calculate a + b
  # a, b: int or string
  def bigint_plus(a, b):
      a = str(a)
      b = str(b)
  
      d = max([len(a), len(b)])
      a = "0" * (d - len(a)) + a
      b = "0" * (d - len(b)) + b
  
      ans = ""
      carry = 0
      for i in range(d):
          s = int(a[-i - 1]) + int(b[-i - 1]) + carry
          carry = s // 10
          ans = str(s % 10) + ans
      else:
          if carry:
              ans = str(carry) + ans
  
      return ans
  
  
  # calculate a - b
  # a, b: int or string
  def bigint_minus(a, b):
      a = str(a)
      b = str(b)
      M = []
      m = []
      sign = ""
  
      if len(a) > len(b) or (len(a) == len(b) and a >= b):
          [M, m] = [a, b]
      else:
          [M, m] = [b, a]
          sign = "-"
      m = "0" * (len(M) - len(m)) + m
  
      ans = ""
      borrow = 0
      for i in range(len(M)):
          s = int(M[-i - 1]) - int(m[-i - 1]) - borrow
          if s < 0:
              borrow = 1
              s += 10
          else:
              borrow = 0
          ans = str(s) + ans
  
      return sign + delete_head_zeros(ans)
  
  
  # calculate a * b
  # a, b: int or string
  def bigint_multiply(a, b):
      a = str(a)
      b = str(b)
  
      md = []
      for j in range(len(b)):
          carry = 0
          mj = ""
          for i in range(len(a)):
              m = int(a[-i - 1]) * int(b[-j - 1]) + carry
              carry = m // 10
              mj = str(m % 10) + mj
          else:
              if carry:
                  mj = str(carry) + mj
          md.append(mj)
  
      ans = 0
      for k in range(len(md)):
          ans = bigint_plus(md[k] + "0" * k, ans)
  
      return ans
  
  
  # calculate a / b to d digits after decimal point
  # a, b, d: int or string
  def bigint_divide(a, b, d=0):
      a = str(a)
      b = str(b)
      d = int(d)
      if d < 0:
          d = 0
  
      ans = ""
      r = ""
      for i in range(len(a) + d):
          q = 0
          if i < len(a):
              r += a[i]
          elif i == len(a):
              ans += "."
              r += "0"
          else:
              r += "0"
  
          if bigint_compare(r, b) == -1:
              ans += str(q)
          else:
              while bigint_compare(r, b) >= 0:
                  r = bigint_minus(r, b)
                  q += 1
              ans += str(q)
  
      return delete_head_zeros(ans)
  
  
  def main():
      N, X = input().split(" ")
      layer = [1]
      patties = [1]
      for i in range(int(N)):
          layer.append(bigint_plus(bigint_multiply(layer[-1], 2), 3))
          patties.append(bigint_plus(bigint_multiply(patties[-1], 2), 1))
  
      def count_patty(L, Y, P):  # Y, P : bigint
          if L == 0:
              return bigint_plus(P, 1)
          center = bigint_divide(bigint_plus(layer[L], 1), 2)
          if Y == "1":
              return P
          elif Y == layer[L]:
              return bigint_plus(P, patties[L])
          elif bigint_compare(Y, center) == 0:
              return bigint_plus(bigint_plus(P, 1), patties[L - 1])
          elif bigint_compare(Y, center) == 1:
              return count_patty(
                  L - 1,
                  bigint_minus(Y, center),
                  bigint_plus(bigint_plus(P, patties[L - 1]), 1),
              )
          elif bigint_compare(Y, center) == -1:
              return count_patty(L - 1, bigint_minus(Y, 1), P)
  
      print(count_patty(int(N), X, "0"))
  
  
  main()
  
problem_description: Statement
  
  In some other world, today is Christmas.
  
  Mr. Takaha decides to make a multi-dimensional burger in his party. A _level-
  L burger_ (L is an integer greater than or equal to 0) is the following thing:
  
    * A level-0 burger is a patty.
    * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom.
  
  For example, a level-1 burger and a level-2 burger look like `BPPPB` and
  `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a
  patty.
  
  The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will
  eat X layers from the bottom of this burger (a layer is a patty or a bun). How
  many patties will she eat?
samples: [{"input": "2 7", "output": "4\n    \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n    \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n    \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]