# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def fib(prev, pprev, mod):
    return (prev + pprev) % mod, prev


def main():
    n, m = get_ln_int_inputs()
    current, prev = 1, 0
    for _ in range(n - 2):
        current, prev = fib(current, prev, m)
    print(current)


main()