n,m=gets.split.map{|e| e.to_i} f1=0 f2=1 3.upto(n){ f3=f1+f2 f1=f2%m f2=f3%m } puts f2