type burger =
  | Level0
  | LevelL of int * int * burger

let patties = function
  | Level0 -> 1
  | LevelL (p, _, _) -> p

let stratos = function
  | Level0 -> 1
  | LevelL (_, s, _) -> s

let rec mkburger = function
  | 0 -> Level0
  | l ->
      let b = mkburger (l - 1) in
      LevelL (2 * patties b + 1, 2 * stratos b + 3, b)

let rec solve x = function
  | Level0 -> max 1 x
  | LevelL (p, s, b) ->
      if x <= 1 then 0
      else if x - 1 <= stratos b then solve (x - 1) b
      else if x - 1 - stratos b <= 1 then patties b + 1
      else patties b + 1 + solve (x - stratos b - 2) b

let () = Scanf.scanf "%d %d" @@ fun n x ->
  Printf.printf "%d\n" @@ solve x @@ mkburger n
