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,long M) { 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 % M; Fn1 = F % M; F = (Fn1 + Fn2) % M; } return F; } }