# -*- coding: utf-8 -*- def fab(k, m): cache = [0, 1] for w in range(k - 1): cache.append((cache[0] + cache[1]) % m) del cache[0] return cache[0] def solve(input): n = int(input.split(" ")[0]) m = int(input.split(" ")[1]) return fab(n,m) if __name__ == "__main__": print solve(raw_input())