#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        cmp::min($x, min!($($y),+))
    };
}

const MOD: usize = 1_000_000_007;
const MAX: usize = 510_000;

struct BinCoeff {
    fac: Vec<usize>,
    finv: Vec<usize>,
    inv: Vec<usize>,
}

impl BinCoeff {
    fn new() -> BinCoeff {
        let fac = vec![0; MAX];
        let finv = vec![0; MAX];
        let inv = vec![0; MAX];
        let mut bincoeff = BinCoeff { fac: fac, finv: finv, inv: inv };
        bincoeff.com_init();
        bincoeff
    }

    fn com_init(&mut self) {
        let fac = &mut self.fac;
        let finv = &mut self.finv;
        let inv = &mut self.inv;
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for i in 2..MAX {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    fn bin_coeff(&mut self, n: usize, k: usize) -> usize {
        if k > n/2 {
            self.bin_coeff(n-k, k)
        } else {
            self.fac[n] * (self.finv[k] * self.finv[n - k] % MOD) % MOD
        }
    }
}

struct UnionFind {
    par: Vec<usize>
}

impl UnionFind {
    fn new(size: usize) -> UnionFind {
        UnionFind {
            par: (0..size).collect::<Vec<usize>>()
        }
    }

    fn root(&mut self, node: usize) -> usize {
        let parent = self.par[node];
        if parent == node { parent }
        else {
            let parent = self.root(parent);
            self.par[node] = parent;
            parent
        }
    }

    fn unite(&mut self, a: usize, b: usize) {
        let root_a = self.root(a);
        let root_b = self.root(b);
        self.par[root_b] = root_a;
    }

    fn is_same(&mut self, a: usize, b: usize) -> bool {
        let root_a = self.root(a);
        let root_b = self.root(b);
        root_a == root_b
    }
}

// must input n <= m
fn gcd(n: usize, m: usize) -> usize {
    if n == 0 {
        m
    } else {
        gcd(m%n, n)
    }
}

use std::{usize, iter, cmp};
use std::collections::{HashSet, BinaryHeap, VecDeque, HashMap};
fn main() {
    input! {
        N: usize,
        X: usize,
    }
    println!("{}", solve(N, X));
}

fn solve(N: usize, X: usize) -> usize {
    let n_layers = (0..N).map(|level| (1 << level + 2) - 3).collect::<Vec<usize>>();
    let n_pates = (0..N).map(|level| (1 << level + 1) - 1).collect::<Vec<usize>>();
    let mut pate = 0;
    let mut rest_of_eatable = X;
    for (&n_layer, &n_pate) in n_layers.iter().zip(n_pates.iter()).rev() {
        if rest_of_eatable <= 1 {
            rest_of_eatable = 0;
            break;
        } else if rest_of_eatable <= 1 + n_layer {
            rest_of_eatable -= 1;
        } else if rest_of_eatable <= 1 + n_layer + 1 {
            pate += n_pate + 1;
            rest_of_eatable = 0;
            break;
        } else if rest_of_eatable <= 1 + n_layer + 1 + n_layer {
            pate += n_pate + 1;
            rest_of_eatable -= 1 + n_layer + 1;
        } else {
            pate += n_pate + 1 + n_pate;
            rest_of_eatable = 0;
            break;
        }
    }
    pate += rest_of_eatable;
    return pate
}

#[test]
fn test_fn0() {
    assert_eq!(solve(2, 0), 0);
}
#[test]
fn test_fn1() {
    assert_eq!(solve(2, 1), 0);
}
#[test]
fn test_fn2() {
    assert_eq!(solve(2, 2), 0);
}
#[test]
fn test_fn3() {
    assert_eq!(solve(2, 3), 1);
}
#[test]
fn test_fn4() {
    assert_eq!(solve(2, 4), 2);
}
#[test]
fn test_fn5() {
    assert_eq!(solve(2, 5), 3);
}
#[test]
fn test_fn6() {
    assert_eq!(solve(2, 6), 3);
}
#[test]
fn test_fn7() {
    assert_eq!(solve(2, 7), 4);
}
#[test]
fn test_fn8() {
    assert_eq!(solve(2, 8), 4);
}
#[test]
fn test_fn9() {
    assert_eq!(solve(2, 9), 5);
}
#[test]
fn test_fn10() {
    assert_eq!(solve(2, 10), 6);
}
#[test]
fn test_fn11() {
    assert_eq!(solve(2, 11), 7);
}
#[test]
fn test_fn12() {
    assert_eq!(solve(2, 12), 7);
}
#[test]
fn test_fn13() {
    assert_eq!(solve(2, 13), 7);
}


Measured memory_bytes: 4352