import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.System.in; public class No526 { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String[] inputs = reader.readLine().split(" "); long N = Long.parseLong(inputs[0]); long M = Long.parseLong(inputs[1]); long fN_1 = 0; long fN_2 = 1; for (long i = 0; i < N - 2; i++) { long tmp = fN_2; fN_2 = (fN_1 + fN_2) % M; fN_1 = tmp; } System.out.println(fN_2 % M); } }