n,m=gets.split.map &:to_i p ((((1+5**(0.5))/2)**(n-1)-((1-5**(0.5))/2)**(n-1))/5**(0.5)).round%m