import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long m = sc.nextInt(); if (n == 1) { System.out.println(0); return; } else if (n == 2) { System.out.println(1); return; } long prepre = 0; long pre = 1; for (int i = 3; i <= n; i++) { long cur = (prepre + pre) % m; prepre = pre; pre = cur; } System.out.println(pre); } }