using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray();
        long hen = inpt[0];
        this.Root = new TreeNode(0);
        this.DepthList.Add(0, new Dictionary<long, TreeNode>());
        this.DepthList[0].Add(0, this.Root);

        long idx = 1;
        for(long i=0; i<hen; i++) {
            this.DepthList.Add(this.DepthList.Count, new Dictionary<long, TreeNode>());
            for(long j=0; j<this.DepthList[i].Count; j++) {
                for(int k=0; k<2; k++) {
                    TreeNode tree = this.DepthList[i][j].AddChild(new TreeNode(idx));
                    if(tree == null) {
                        continue;
                    }
                    idx++;
                    this.DepthList[i + 1].Add(DepthList[i+1].Count, tree);
                }
            }
        }

        long ans = 0;

        Dir d = Dir.Right;

        TreeNode current = this.DepthList[inpt[1]][0];
        for(long i=0; i<this.DepthList.Sum(a=>a.Value.Count); i++) {
            Dir next = this.Turn(current, d);
            if(next == Dir.None) {
                break;
            }
            ans++;
            current.Visited = true;
            if(next == Dir.DownLeft) {
                current.HasMoveDownLeft = true;
                current = current.LeftChild;
            } else if(next == Dir.DownRight) {
                current.HasMoveDownRight = true;
                current = current.RightChild;
            } else if(next == Dir.UpLeft) {
                current.HasMoveUpLeft = true;
                current = current.LeftParent;
            } else if(next == Dir.UpRight) {
                current.HasMoveUpRight = true;
                current = current.RightParent;
            } else if(next == Dir.Left) {
                current.HasMoveLeft = true;
                current = current.PrevSibling;
            } else if(next == Dir.Right) {
                current.HasMoveRight = true;
                current = current.NextSibling;
            }
            d = next;
        }
        Console.WriteLine(ans);
    }

    private Dir Turn(TreeNode trr, Dir now) {
        if(now == Dir.Left) {
            if(trr.HasMoveUpLeft && trr.HasMoveDownRight) {
                if(!trr.HasMoveUpRight) {
                    return Dir.UpRight;
                }
            } else if(trr.HasMoveUpRight && trr.HasMoveDownLeft) {
                if(!trr.HasMoveDownRight) {
                    return Dir.DownRight;
                }
            } else if(trr.PrevSibling == null) {
                if(!trr.HasMoveDownRight) {
                    return Dir.DownRight;
                }
            } else if(!trr.HasMoveLeft)
            {
                return now;
            }
        } else if(now == Dir.Right) {
            if(trr.HasMoveUpLeft && trr.HasMoveDownRight) {
                if(!trr.HasMoveDownLeft) {
                    return Dir.DownLeft;
                }
            } else if(trr.HasMoveUpRight && trr.HasMoveDownLeft) {
                if(!trr.HasMoveUpLeft) {
                    return Dir.UpLeft;
                }
            } else if(trr.NextSibling == null) {
                if(!trr.HasMoveDownLeft) {
                    return Dir.DownLeft;
                }
            } else if(!trr.HasMoveRight) {
                return now;
            }
        } else if(now == Dir.DownLeft) {
            if(trr.HasMoveUpLeft && trr.HasMoveDownRight) {
                if(!trr.HasMoveRight) {
                    return Dir.Right;
                }
            } else if(trr.HasMoveLeft && trr.HasMoveRight) {
                if(!trr.HasMoveUpLeft) {
                    return Dir.UpLeft;
                }
            } else if(trr.LeftChild == null) {
                if(!trr.HasMoveUpLeft) {
                    return Dir.UpLeft;
                }
            } else if(!trr.HasMoveDownLeft) {
                return now;
            }
        } else if(now == Dir.DownRight) {
            if(trr.HasMoveUpRight && trr.HasMoveDownLeft) {
                if(!trr.HasMoveLeft) {
                    return Dir.Left;
                }
            } else if(trr.HasMoveLeft && trr.HasMoveRight) {
                if(!trr.HasMoveUpRight) {
                    return Dir.UpRight;
                }
            } else if(trr.RightChild == null) {
                if(!trr.HasMoveUpRight) {
                    return Dir.UpRight;
                }
            } else if(!trr.HasMoveDownRight)
            {
                return now;
            }
        } else if(now == Dir.UpLeft) {
            if(trr.HasMoveDownLeft && trr.HasMoveUpRight) {
                if(!trr.HasMoveRight) {
                    return Dir.Right;
                }
            } else if(trr.HasMoveRight && trr.HasMoveLeft) {
                if(!trr.HasMoveDownLeft) {
                    return Dir.DownLeft;
                }
            } else if(trr.LeftParent == null) {
                if(!trr.HasMoveRight) {
                    return Dir.Right;
                }
            } else if(!trr.HasMoveUpLeft) {
                return now;
            }
        } else if(now == Dir.UpRight) {
            if(trr.HasMoveDownRight && trr.HasMoveUpLeft) {
                if(!trr.HasMoveLeft) {
                    return Dir.Left;
                }
            } else if(trr.HasMoveLeft && trr.HasMoveRight) {
                if(!trr.HasMoveDownRight) {
                    return Dir.DownRight;
                }
            } else if(trr.RightParent == null) {
                if(!trr.HasMoveLeft) {
                    return Dir.Left;
                }
            }  else if(!trr.HasMoveUpRight)
            {
                 return now;
            }
        }
        return Dir.None;
    }

    private enum Dir {
        UpLeft,
        UpRight,
        DownLeft,
        DownRight,
        Left,
        Right,
        None
    }

    private TreeNode Root;

    private Dictionary<long, Dictionary<long, TreeNode>> DepthList = new Dictionary<long, Dictionary<long, TreeNode>>();

    public class TreeNode {
        public bool Visited = false;
        public TreeNode LeftParent;
        public TreeNode RightParent;
        public TreeNode NextSibling;
        public TreeNode PrevSibling;

        public TreeNode LeftChild;
        public TreeNode RightChild;

        private bool mMoveRight = false;
        public bool HasMoveRight {
            get{return this.mMoveRight;}
            set{
                this.mMoveRight = value;
                if(this.NextSibling != null && this.NextSibling.HasMoveLeft != value) {
                    this.NextSibling.HasMoveLeft = value;
                }
            }
        }

        private bool mMoveLeft = false;

        public bool HasMoveLeft {
            get{return this.mMoveLeft;}
            set {
                this.mMoveLeft = value;
                if(this.PrevSibling != null && this.PrevSibling.HasMoveRight != value) {
                    this.PrevSibling.HasMoveRight = value;
                }
            }
        }

        private bool mMoveDownRight = false;

        public bool HasMoveDownRight {
            get {
                return this.mMoveDownRight;
            }
            set {
                this.mMoveDownRight = value;
                if(this.RightChild != null && this.RightChild.HasMoveUpLeft != value) {
                    this.RightChild.HasMoveUpLeft = value;
                }
            }
        }
        private bool mMoveDownLeft = false;

        public bool HasMoveDownLeft {
            get {
                return this.mMoveDownLeft;
            }
            set {
                this.mMoveDownLeft = value;
                if(this.LeftChild != null && this.LeftChild.HasMoveUpRight != value) {
                    this.LeftChild.HasMoveUpRight = value;
                } 
            }
        }
        private bool mMoveUpRight = false;

        public bool HasMoveUpRight {
            get { return this.mMoveUpRight;}
            set {
                this.mMoveUpRight = value;
                if(this.RightParent != null && this.RightParent.HasMoveDownLeft != value) {
                    this.RightParent.HasMoveDownLeft = value;
                }
            }
        }
        private bool mMoveUpLeft = false;

        public bool HasMoveUpLeft {
            get {return this.mMoveUpLeft;}
            set {
                this.mMoveUpLeft = value;
                if(this.LeftParent != null && this.LeftParent.HasMoveDownRight != value) {
                    this.LeftParent.HasMoveDownRight = value;
                }
            }
        }
        public long Id;
        public TreeNode(long id) {
            this.Id = id;
        }

        public int Depth;
        public TreeNode AddChild(TreeNode addChild) {
            if(this.LeftChild == null) {
                this.LeftChild = addChild;
                addChild.RightParent = this;
                addChild.Depth = this.Depth + 1;
                return addChild;
            } else if(this.RightChild == null) {
                this.RightChild = addChild;
                addChild.LeftParent = this;
                this.LeftChild.NextSibling = addChild;
                addChild.PrevSibling = this.LeftChild;
                if(this.NextSibling != null) {
                    this.NextSibling.LeftChild = addChild;
                    addChild.RightParent = this.NextSibling;
                }
                addChild.Depth = this.Depth + 1;
                return addChild;
            }
            return null;
        }
    }

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


5 2

 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }

    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}