let rec solve patties stratos x = function
  | 0 -> x
  | l ->
      if x <= 1 then 0
      else if x - 1 <= stratos (l - 1) then
        solve patties stratos (x - 1) (l - 1)
      else if x - 1 - stratos (l - 1) <= 1 then
        patties (l - 1) + 1
      else if x - 2 - stratos (l - 1) <= stratos (l - 1) then
        patties (l - 1) + 1 + solve patties stratos (x - 2 - stratos (l - 1)) (l - 1)
      else patties l

let () = Scanf.scanf "%d %d" @@ fun n x ->
  let patties = Array.make (n + 1) 1 in
  for i = 1 to n do
    patties.(i) <- 2 * patties.(i - 1) + 1
  done;
  let stratos = Array.make (n + 1) 1 in
  for i = 1 to n do
    stratos.(i) <- 2 * stratos.(i - 1) + 3
  done;
  Printf.printf "%d\n" @@ solve (Array.get patties) (Array.get stratos) x n
