open Printf
open Scanf

let (++) = Int64.add
let (--) = Int64.sub
let ( ** ) = Int64.mul
let long = Int64.of_int
let succl = Int64.succ
let predl = Int64.pred

let read_long _ = bscanf Scanning.stdin " %Ld " (fun x -> x)

let rec height = function
  | x when x < 0L -> 0L
  | 0L -> 1L
  | n -> 3L ++ 2L ** height (predl n)

let rec pate = function
  | x when x < 0L -> 0L
  | 0L -> 1L
  | n -> 1L ++ 2L ** pate (predl n)

let rec count n k =
  let h = height n in
  match k with
  | 0L -> 0L
  | _ when h = k -> pate n
  | _ ->
    let h' = height (predl n) in
    if h' >= (predl k)
    then count (predl n) (predl k)
    else count (predl n) h' ++ 1L ++ count (predl n) (k--h'--2L)

let () =
  let n = read_long () in
  let x = read_long () in
  printf "%Ld\n" @@ count n x
