(defn input []
  (->> (clojure.string/split (read-line) #"\s")
    (map #(bigint %))))

(defn ^:dynamic inner-func [Level]
  (if (zero? Level)
    "P"
    (str
      "B"
      (#'inner-func (dec Level))
      "P"
      (#'inner-func (dec Level))
      "B")))

(defn Christmas [[N X]]
  (binding [inner-func (memoize inner-func)]
    (->> (inner-func N)
      (take-last X)
      (filter #(= (str %) "P"))
      count)))

(->> (input)
  Christmas
  println)
