# -*- coding: utf-8 -*- cache = {1 : 0, 2 : 1} def fab(k): if k < 1: return 0 elif k in cache: return cache[k] else: cache[k] = fab(k - 1) + fab(k - 2) return cache[k] def solve(input): n = int(input.split(" ")[0]) m = int(input.split(" ")[1]) return fab(n) % m if __name__ == "__main__": print solve(raw_input())