import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

const MOD = 1001;

int[] CalcFib(int V) {
    int[] Ret = new int[V];
    Ret[0] = 2; Ret[1] = 3;
    for (int i = 2; i < V; i++) {
        Ret[i] = (Ret[i - 1] + Ret[i - 2]) % MOD;
    }
    return Ret;
}
 
void main() {
    int V, d;

    const fib = CalcFib(1000);

    void solve() {
        //writeln([V, d]);
        bool[][] G = new bool[][](V, V);
        foreach (i; 0 .. V) {
            foreach (j; 0 .. V) {
                if (abs(fib[i] - fib[j]) < d) {
                    G[i][j] = true;
                }
            }
        }

        bool[] used = new bool[V];
        void dfs(int v) {
            used[v] = true;
            foreach (i; 0 .. V) {
                if (!used[i] && G[v][i]) {
                    dfs(i);
                }
            }
        }

        int Ans = 0;
        foreach (i; 0 .. V) {
            if (!used[i]) {
                //write([i]);
                dfs(i);
                Ans++;
            }
        }
        writeln(Ans);
    }

    while (readf("%d %d\n", &V, &d)) {
        //writeln(fib[0 .. V]);
        solve();
    }
}