n, x = gets.split.map(&:to_i)
# n, x = 2, 8

# require 'tapp'
# [n, x].tapp
@memo = {}
@memo[0] = [1, 1]
def trav(level, rest)
  # [level, rest].tapp
  if @memo[level] && @memo[level][0] <= rest
    return @memo[level]
  end

  eaten_total = 0
  forward_total = 0

  forward_total += 1
  rest -= 1
  if rest == 0
    return [forward_total, eaten_total]
  end

  forward, eaten = trav(level - 1, rest)
  forward_total += forward
  rest -= forward
  eaten_total += eaten
  if rest == 0
    return [forward_total, eaten_total]
  end

  forward_total += 1
  rest -= 1
  eaten_total += 1
  if rest == 0
    return [forward_total, eaten_total]
  end

  forward, eaten = trav(level - 1, rest)
  forward_total += forward
  rest -= forward
  eaten_total += eaten
  if rest == 0
    return [forward_total, eaten_total]
  end

  forward_total += 1
  rest -= 1

  @memo[level] = [forward_total, eaten_total]

  return [forward_total, eaten_total]
end

# n = 2
# x = 7
forward, eaten = trav(n, x)
puts eaten
