using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        static long[] array;
        static long[] len;

        public static void Main() {
            var N = NextInt();
            var X = NextLong();
            array = new long[N + 1];
            len = new long[N + 1];

            array[0] = 1;
            len[0] = 1;
            for (int i = 1; i <= N; i++) {
                array[i] = 2 * array[i - 1] + 1;
                len[i] = 2 * len[i - 1] + 3;
            }

            Console.WriteLine(Count(X, N));
        }

        public static long Count(long length, int n) {

            if (len[n] == length) return array[n];
                
            if(length <= 1) {
                return 0;
            } else if(length <= len[n - 1] + 1) {
                return Count(length - 1, n - 1);
            } else if(length == len[n - 1] + 2) {
                return array[n - 1] + 1;
            } else if(length <= 2 * len[n - 1] + 2) {
                return array[n - 1] + Count(length - len[n - 1] - 2, n - 1) + 1;
            } else {
                return array[n];
            }
        }
    }

    class MyMath {
        public static long mod = 1000000007;

        public static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static List<long> Factor(long n) {
            var list = new List<long>();
            n = DivideToLimit(n, 2, list);
            n = DivideToLimit(n, 3, list);
            long sqrt = Sqrt(n);
            for (int i = 5; i <= n && i <= sqrt; i += 4) {
                n = DivideToLimit(n, i, list);
                i += 2;
                n = DivideToLimit(n, i, list);
            }
            if (n > 1) list.Add(n);
            return list;
        }

        public static long Sqrt(long n) {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2) {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        static long DivideToLimit(long divisor, long dividend, List<long> list) {
            while (divisor % dividend == 0) {
                list.Add(dividend);
                divisor /= dividend;
            }
            return divisor;
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268