import java.util.Scanner; public class No526 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long M = sc.nextLong(); System.out.println(fibonacci(N) % M); } static long fibonacci(long N) { if(N == 1) { return 0; } if(N == 2) { return 1; } long F,Fn1,Fn2; F = 1;Fn1 = 0; for(int i = 3;i <= N;i++) { Fn2 = Fn1; Fn1 = F; F = Fn1 + Fn2; } return F; } }