#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<deque>
using namespace std;

int main() {

    int v, d;
    while(cin >> v >> d && (v || d)) {
        deque<int> fib (v);
        fib[0] = 2;
        fib[1] = 3;
        for(int i = 2; i < v; i++) {
            fib[i] = (fib[i-1] + fib[i-2]) % 1001;
        }
        sort(fib.begin(), fib.end());

        int sets = 1;
        int now = fib.front();
        fib.pop_front();
        while(!fib.empty()) {
            if(fib.front() - now >= d) {
                sets += 1;
            }
            now = fib.front();
            fib.pop_front();
        }

        cout << sets << endl;

    }
     
    return 0;
}