import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); long prepre = 0; long pre = 1; for (int i = 3; i <= n; i++) { long now = (pre + prepre) % m; prepre = pre; pre = now; } System.out.println(pre); } }