#!/usr/bin/python3

# I can't see the logic behind their example: 5 months, k=3,
# and that returns... 19? What the fuck?

# OH WAIT, LEONARDO DE PISA'S MODEL.
# OH.

# So the rabbits reach reproductive age after a month.

import sys
import re

def rabbits_debug(n, k, rp=0, gp=1):
    """rp stands for "reproductive population" and gp for "growing"."""
    assert 41 > n and n > 0 and 6 > k and k > 0
    pop = rp + gp
    if (n == 1):
        print("rabbits({}, {}, {}, {}): pop {} (final)".format(n, k, rp, gp, pop))
        return rp+gp # No time to breed! ... I guess.
    else:
        print("rabbits({}, {}, {}, {}): pop {}".format(n, k, rp, gp, pop))
        return rabbits_debug( (n-1), k, rp=pop, gp=k*rp)

def rabbits(n, k, rp=0, gp=1):
    """Finished recurrence pattern for Rosalind's Fibonacci de
    Pisa rabbit population extension."""
    assert isinstance(n, int) and 41 > n and n > 0, "n malformed"
    assert isinstance(k, int) and 6 > k and k > 0, "k malformed"
    pop = rp + gp
    if (n == 1):
        return rp+gp
    else:
        return rabbits( (n-1), k, rp=pop, gp=k*rp)

# Alright, let's hope this goes a bit better this time.

if __name__=="__main__":
    for line in sys.stdin:
        x = map(int,re.sub("[^\w]", " ",  line).split())
        print(rabbits(x.__next__(), x.__next__()))

