n,m = map(int, raw_input().split()) a = 0 b = 1 i = 2 while i < n: c = (a + b) % m a = b b = c i += 1 if i == 0: print a else: print b