#import <stdio.h>

long long f(int n, long x) {
    if (n==0) return 1LL;
    if (x<=1) return 0LL;

    long long p = 1LL<<(n+1);

    if (x<p-1LL) {
        return f(n-1,x-1);
    } else if (x==p-1) {
        return p/2LL;
    } else if (x>=2LL*p-3LL) {
        return p-1LL;
    } else {
        return p/2LL+f(n-1,x-p+1);
    }
}

int main(){
    int n;
    long long x;
    scanf("%d %lld",&n,&x);
    printf("%lld\n", f(n,x));
    return 0;
}


; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_403/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_403/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@.str = private unnamed_addr constant [8 x i8] c"%d %lld\00", align 1
@.str.1 = private unnamed_addr constant [6 x i8] c"%lld\0A\00", align 1

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i64 @f(i32 noundef %n, i64 noundef %x) local_unnamed_addr #0 {
entry:
  %cmp4654 = icmp eq i32 %n, 0
  br i1 %cmp4654, label %return, label %if.end.lr.ph

if.end.lr.ph:                                     ; preds = %entry, %if.else16
  %x.tr.ph57 = phi i64 [ %add20, %if.else16 ], [ %x, %entry ]
  %n.tr.ph56 = phi i32 [ %sub18, %if.else16 ], [ %n, %entry ]
  %accumulator.tr.ph55 = phi i64 [ %add22, %if.else16 ], [ 0, %entry ]
  br label %if.end

if.end:                                           ; preds = %if.end.lr.ph, %if.then5
  %x.tr48 = phi i64 [ %x.tr.ph57, %if.end.lr.ph ], [ %sub7, %if.then5 ]
  %n.tr47 = phi i32 [ %n.tr.ph56, %if.end.lr.ph ], [ %sub6, %if.then5 ]
  %cmp1 = icmp slt i64 %x.tr48, 2
  br i1 %cmp1, label %return, label %if.end3

if.end3:                                          ; preds = %if.end
  %add = add nsw i32 %n.tr47, 1
  %sh_prom = zext i32 %add to i64
  %shl = shl nuw i64 1, %sh_prom
  %sub = add nsw i64 %shl, -1
  %cmp4 = icmp sgt i64 %sub, %x.tr48
  br i1 %cmp4, label %if.then5, label %if.else

if.then5:                                         ; preds = %if.end3
  %sub6 = add nsw i32 %n.tr47, -1
  %sub7 = add nsw i64 %x.tr48, -1
  %cmp = icmp eq i32 %sub6, 0
  br i1 %cmp, label %return, label %if.end

if.else:                                          ; preds = %if.end3
  %cmp9 = icmp eq i64 %sub, %x.tr48
  br i1 %cmp9, label %if.then10, label %if.else11

if.then10:                                        ; preds = %if.else
  %div = sdiv i64 %shl, 2
  br label %return

if.else11:                                        ; preds = %if.else
  %mul = shl i64 2, %sh_prom
  %sub12 = add nsw i64 %mul, -3
  %cmp13.not = icmp sgt i64 %sub12, %x.tr48
  br i1 %cmp13.not, label %if.else16, label %return

if.else16:                                        ; preds = %if.else11
  %div17 = sdiv i64 %shl, 2
  %sub18 = add nsw i32 %n.tr47, -1
  %sub19 = add nuw nsw i64 %x.tr48, 1
  %add20 = sub i64 %sub19, %shl
  %add22 = add nsw i64 %div17, %accumulator.tr.ph55
  %cmp46 = icmp eq i32 %sub18, 0
  br i1 %cmp46, label %return, label %if.end.lr.ph

return:                                           ; preds = %if.else16, %if.else11, %if.then5, %if.end, %entry, %if.then10
  %accumulator.tr.ph44 = phi i64 [ %accumulator.tr.ph55, %if.then10 ], [ 0, %entry ], [ %accumulator.tr.ph55, %if.end ], [ %accumulator.tr.ph55, %if.then5 ], [ %add22, %if.else16 ], [ %accumulator.tr.ph55, %if.else11 ]
  %retval.1 = phi i64 [ %div, %if.then10 ], [ 1, %entry ], [ 1, %if.then5 ], [ 0, %if.end ], [ 1, %if.else16 ], [ %sub, %if.else11 ]
  %accumulator.ret.tr = add nsw i64 %retval.1, %accumulator.tr.ph44
  ret i64 %accumulator.ret.tr
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #2 {
entry:
  %n = alloca i32, align 4
  %x = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %n) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %x) #4
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n, ptr noundef nonnull %x)
  %0 = load i32, ptr %n, align 4, !tbaa !5
  %cmp4654.i = icmp eq i32 %0, 0
  br i1 %cmp4654.i, label %f.exit, label %if.end.lr.ph.i.preheader

if.end.lr.ph.i.preheader:                         ; preds = %entry
  %1 = load i64, ptr %x, align 8, !tbaa !9
  br label %if.end.lr.ph.i

if.end.lr.ph.i:                                   ; preds = %if.end.lr.ph.i.preheader, %if.else16.i
  %x.tr.ph57.i = phi i64 [ %add20.i, %if.else16.i ], [ %1, %if.end.lr.ph.i.preheader ]
  %n.tr.ph56.i = phi i32 [ %sub18.i, %if.else16.i ], [ %0, %if.end.lr.ph.i.preheader ]
  %accumulator.tr.ph55.i = phi i64 [ %add22.i, %if.else16.i ], [ 0, %if.end.lr.ph.i.preheader ]
  br label %if.end.i

if.end.i:                                         ; preds = %if.then5.i, %if.end.lr.ph.i
  %x.tr48.i = phi i64 [ %x.tr.ph57.i, %if.end.lr.ph.i ], [ %sub7.i, %if.then5.i ]
  %n.tr47.i = phi i32 [ %n.tr.ph56.i, %if.end.lr.ph.i ], [ %sub6.i, %if.then5.i ]
  %cmp1.i = icmp slt i64 %x.tr48.i, 2
  br i1 %cmp1.i, label %f.exit, label %if.end3.i

if.end3.i:                                        ; preds = %if.end.i
  %add.i = add nsw i32 %n.tr47.i, 1
  %sh_prom.i = zext i32 %add.i to i64
  %shl.i = shl nuw i64 1, %sh_prom.i
  %sub.i = add nsw i64 %shl.i, -1
  %cmp4.i = icmp sgt i64 %sub.i, %x.tr48.i
  br i1 %cmp4.i, label %if.then5.i, label %if.else.i

if.then5.i:                                       ; preds = %if.end3.i
  %sub6.i = add nsw i32 %n.tr47.i, -1
  %sub7.i = add nsw i64 %x.tr48.i, -1
  %cmp.i = icmp eq i32 %sub6.i, 0
  br i1 %cmp.i, label %f.exit, label %if.end.i

if.else.i:                                        ; preds = %if.end3.i
  %cmp9.i = icmp eq i64 %sub.i, %x.tr48.i
  br i1 %cmp9.i, label %if.then10.i, label %if.else11.i

if.then10.i:                                      ; preds = %if.else.i
  %div.i = sdiv i64 %shl.i, 2
  br label %f.exit

if.else11.i:                                      ; preds = %if.else.i
  %mul.i = shl i64 2, %sh_prom.i
  %sub12.i = add nsw i64 %mul.i, -3
  %cmp13.not.i = icmp sgt i64 %sub12.i, %x.tr48.i
  br i1 %cmp13.not.i, label %if.else16.i, label %f.exit

if.else16.i:                                      ; preds = %if.else11.i
  %div17.i = sdiv i64 %shl.i, 2
  %sub18.i = add nsw i32 %n.tr47.i, -1
  %sub19.i = add nuw nsw i64 %x.tr48.i, 1
  %add20.i = sub i64 %sub19.i, %shl.i
  %add22.i = add nsw i64 %div17.i, %accumulator.tr.ph55.i
  %cmp46.i = icmp eq i32 %sub18.i, 0
  br i1 %cmp46.i, label %f.exit, label %if.end.lr.ph.i

f.exit:                                           ; preds = %if.else11.i, %if.else16.i, %if.end.i, %if.then5.i, %entry, %if.then10.i
  %accumulator.tr.ph44.i = phi i64 [ %accumulator.tr.ph55.i, %if.then10.i ], [ 0, %entry ], [ %accumulator.tr.ph55.i, %if.then5.i ], [ %accumulator.tr.ph55.i, %if.end.i ], [ %accumulator.tr.ph55.i, %if.else11.i ], [ %add22.i, %if.else16.i ]
  %retval.1.i = phi i64 [ %div.i, %if.then10.i ], [ 1, %entry ], [ 0, %if.end.i ], [ 1, %if.then5.i ], [ %sub.i, %if.else11.i ], [ 1, %if.else16.i ]
  %accumulator.ret.tr.i = add nsw i64 %retval.1.i, %accumulator.tr.ph44.i
  %call2 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %accumulator.ret.tr.i)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %x) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %n) #4
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { nofree norecurse nosync nounwind memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
