open Printf open Scanf
module Lib = struct
  let i32,i64,ist = Int64.(to_int,of_int,to_string)
  let (+$) = (+) let (-$) = (-) let (/$) = (/) let ( *$) = ( * ) let (%$) = (mod)
  let labs = Int64.abs
  let (+),(-),( * ),(/),(mod),(%) = Int64.(add,sub,mul,div,rem,rem)
  let (+=) r v = r := !r + v
  let (-=) r v = r := !r - v
  let ( *= ) r v = r := !r * v
  let (/=) r v = r := !r / v
  let (%=) r v = r := !r % v
  let max_i64,min_i64 = Int64.(max_int,min_int)
  (* math *)
  let ceildiv p q = (p+q-1L) / q
  let rec gcd m n = match m,n with | m,0L -> m | m,n -> gcd n (m mod n)
  let lcm m n = m / gcd m n * n
  module Int64_infix = struct
    let (land),(lor),(lxor),lnot,(lsl),(lsr),(asr) =
      let open Int64 in
      (logand),(logor),(logxor),lognot,
      (fun u v -> shift_left u (i32 v)),
      (fun u v -> shift_right u (i32 v)),
      (fun u v -> shift_right_logical u (i32 v))
  end
  let pow n k =
    let rec f a n = function
    | 0L -> a | 1L -> n*a | k when k mod 2L = 0L -> f a (n*n) (k/2L) | k -> f (a*n) (n*n) (k/2L)
    in f 1L n k
  (* input *)
  let input_i64_array n = Array.init (i32 n) (fun _ -> Scanf.scanf " %Ld" (fun v -> v))
  let get_i64 _ = Scanf.scanf " %Ld" (fun v -> v)
  let get_2_i64 _ = Scanf.scanf " %Ld %Ld" (fun u v -> u,v)
  let get_3_i64 _ = Scanf.scanf " %Ld %Ld %Ld" (fun u v w -> u,v,w)
  let get_4_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld" (fun u v w x -> u,v,w,x)
  let get_5_i64 _ = Scanf.scanf " %Ld %Ld %Ld %Ld %Ld" (fun u v w x y -> u,v,w,x,y)
  let i32_get_int _ = Scanf.scanf " %d" (fun v -> v) let i32_get_2_ints _ = Scanf.scanf " %d %d" (fun u v -> u,v) let i32_get_3_ints _ = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w) let i32_get_4_ints _ = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x) let i32_get_5_ints _ = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
  (* utils *)
  external id : 'a -> 'a = "%identity"
  let ( *< ) f g x = f (g x)
  let ( *> ) f g x = g (f x)
  let rv f p q = f q p (* ex. 24 |> rv (/) 6 *)
  let alen a = i64 @@ Array.length a
  let llen l = i64 @@  List.length l
  let string_of_list ?(separator=" ") f ls = ls |> List.map f |> String.concat separator
  let string_of_array ?(separator=" ") f a = a |> Array.to_list |> string_of_list ~separator f
  let char_list_of_string str = let rec f0 i a = if i<0 then a else f0 (i-$1) (str.[i]::a) in f0 (String.length str -$ 1) []
  let string_of_char_list ls = List.fold_left (fun u v -> u ^ (String.make 1 v)) "" ls
  let fail _ = failwith "fail"
  let dx,dy = [|1;0;-1;0|],[|0;1;0;-1|]
  let range l r = let ls = ref [] in for i=i32 l to i32 r do ls := i :: !ls done;!ls |> List.rev
  let cartesian_product u v = u |> List.map (fun p -> List.map (fun q -> p,q) v) |> List.flatten
  let shuffle a = Array.sort (fun _ _ -> (Random.int 3) -$ 1) a
  let binary_search ng ok f = let d = if ng < ok then 1L else -1L in
    let rec f0 ng ok =
      if labs (ok - ng) <= 1L then ok
      else let mid = ng + (ok - ng) / 2L in if f mid then f0 ng mid else f0 mid ok
    in f0 (ng-1L*d) (ok+1L*d)
  let lower_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >= v)
  let upper_bound a v = binary_search 0L (alen a - 1L) (fun i -> a.(i32 i) >  v)
  let equal_range a v = lower_bound a v, upper_bound a v (* #=snd-fst *)
  let rec fix f x = f (fix f) x
  let fix_memo ?(size=10000) f x =
    let tb = Hashtbl.create ~random:true size in
    let rec f0 x =
      try Hashtbl.find tb x with
      | Not_found -> (let v = f f0 x in Hashtbl.add tb x v; v)
    in f0 x
  (* imperative *)
  let rep f t ?(stride=1L) fbod = let i = ref f in while !i <= t do fbod !i; i := !i + stride done
  let repb f t ?(stride=1L) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i + stride done
  let repm f t ?(stride=1L) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i + stride done; !m
  let repi f t ?(stride=1) fbod = let i = ref f in while !i <= t do fbod !i; i := !i +$ stride done
  let repib f t ?(stride=1) fbod = let i,c = ref f,ref true in while !i <= t && !c do
    match fbod !i with | `Break -> c := false | `Ok -> i := !i +$ stride done
  let repim f t ?(stride=1) m0 fbod =
    let i,c,m = ref f,ref true,ref m0 in
    while !i<=t && !c do match fbod !m !i with
    | `Break -> c := false | `Break_m m' -> (c := false; m := m') | `Ok m' -> m := m'; i := !i +$ stride done; !m
  let rep_rev f t ?(stride=1L) fbod = rep t f ~stride @@ fun v -> fbod @@ f + t - v
  let repb_rev f t ?(stride=1L) fbod = repb t f ~stride @@ fun v -> fbod @@ f + t - v
  let repm_rev f t ?(stride=1L) m0 fbod = repm f t ~stride m0 @@ fun u v -> fbod u @@ f + t - v
  let repi_rev f t ?(stride=1) fbod = repi t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repib_rev f t ?(stride=1) fbod = repib t f ~stride @@ fun v -> fbod @@ f +$ t -$ v
  let repim_rev f t ?(stride=1) m0 fbod = repim f t ~stride m0 @@ fun u v -> fbod u @@ f +$ t -$ v
  (* output *)
  let print_list_mle f ls = string_of_list f ls |> print_endline
  let print_array_mle f a = string_of_array f a |> print_endline
  let print_list f ls = ls |> List.iter (fun v -> printf "%s " @@ f v); print_newline ()
  let print_array f a = a |> Array.iter (fun v -> printf "%s " @@ f v); print_newline ()
  (* debug *)
  let dump_2darr f a = a |> Array.iter (fun b -> print_array f b)
  let dump_i64_list ls = print_list ist ls
  let dump_i64_array a = print_array ist a
end open Lib open Array

let h = [|1L;
5L; 13L; 29L; 61L; 125L; 253L; 509L; 1021L; 2045L; 4093L; 8189L; 16381L; 32765L; 65533L; 131069L; 262141L; 524285L; 1048573L; 2097149L; 4194301L; 8388605L; 16777213L; 33554429L; 67108861L; 134217725L; 268435453L; 536870909L; 1073741821L; 2147483645L; 4294967293L; 8589934589L; 17179869181L; 34359738365L; 68719476733L; 137438953469L; 274877906941L; 549755813885L; 1099511627773L; 2199023255549L; 4398046511101L; 8796093022205L; 17592186044413L; 35184372088829L; 70368744177661L; 140737488355325L; 281474976710653L; 562949953421309L; 1125899906842621L; 2251799813685245L; 4503599627370493L;|]
let rec f lv ofs =
  let p = h.(lv) in
  let q = p/2L in
  let r = h.(lv-$1) in
  (* printf "%d: ofs=%Ld; %Ld; %Ld; %Ld;\n" lv ofs p q r; *)
  if lv=1 then (match ofs with
    | 1L -> 0L
    | 2L -> 1L
    | 3L -> 2L
    | 4L -> 3L
    | 5L -> 3L
    | _ -> fail 0
  ) else
  if ofs = 1L then 0L
  else if ofs <= 1L + r then 0L + f (lv-$1) (ofs-1L)
  else if ofs = 2L + r then 1L + f (lv-$1) r
  else if ofs <= 2L + r + r then 1L + f (lv-$1) r + f (lv-$1) (ofs-2L-r)
  else if ofs = 3L + r + r then 1L + 2L * f (lv-$1) r
  else fail 0
  (* if ofs < p then 1L + f (lv-$1) (ofs-1L)
  else if ofs = p then 2L + f (lv-$1) p
  else if  *)
let () =
  let n,x = get_2_i64 0 in
  printf "%Ld\n" @@ f (i32 n) x

(* let layers = [5; 13; 29; 61; 125; 253; 509; 1021; 2045; 4093; 8189; 16381; 32765; 65533; 131069; 262141; 524285; 1048573; 2097149; 4194301; 8388605; 16777213; 33554429; 67108861; 134217725; 268435453; 536870909; 1073741821; 2147483645; 4294967293; 8589934589; 17179869181; 34359738365; 68719476733; 137438953469; 274877906941; 549755813885; 1099511627773; 2199023255549; 4398046511101; 8796093022205; 17592186044413; 35184372088829; 70368744177661; 140737488355325; 281474976710653; 562949953421309; 1125899906842621; 2251799813685245; 4503599627370493;] *)

(* let layers = [|5; 13; 29; 61; 125; 253; 509; 1021; 2045; 4093; 8189; 16381; 32765; 65533; 131069; 262141; 524285; 1048573; 2097149; 4194301; 8388605; 16777213; 33554429; 67108861; 134217725; 268435453; 536870909; 1073741821; 2147483645; 4294967293; 8589934589; 17179869181; 34359738365; 68719476733; 137438953469; 274877906941; 549755813885; 1099511627773; 2199023255549; 4398046511101; 8796093022205; 17592186044413; 35184372088829; 70368744177661; 140737488355325; 281474976710653; 562949953421309; 1125899906842621; 2251799813685245; 4503599627370493;|]
let () =
  let n,x = get_2_i64 0 in
  let p = layers.(i32 n) in
  if x>p then  *)
(* let () =
  (* let n,x = get_2_i64 0 in *)
  let a = make 50 0L in
  a.(0) <- 5L;
  repi 1 49 (fun i ->
    a.(i) <- a.(i-$1)*2L + 3L
  );
  print_array (sprintf "%LdL;") a *)











Measured memory_bytes: 384