main(V,d){
	for(;~scanf("%d%d",&V,&d);){
		int f[1001]={0},a=1,b=1,c;
		for(;V--;){
			c=a+b;
			f[c%=1001]=1;
			a=b;
			b=c;
		}
		c=-1e4;
		b=0;
		for(a=0;a<1001;a++){
			if(++c==d)
				b++;
			if(f[a]==1)
				c=0;
		}
		if(c<d)
			b++;
		printf("%d\n",b);
	}
}