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

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            par[x] += par[y]; par[y] = x;
        }
    }

    int distinct() {
        int res = 0;
        for(int i = 0; i < (int)par.size(); i++) res += (par[i] < 0);
        return res;
    }
};

const int MOD = 1001;

int main() {
    vector<int> fib(1001);
    fib[0] = 1, fib[1] = 2;
    for(int i = 2; i <= 1000; i++) {
        fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
    }
    for(int V, D; cin >> V >> D; ) {
        UnionFind uf(V);
        for(int i = 1; i <= V; i++) {
            for(int j = 1; j <= V; j++) {
                if(abs(fib[i] - fib[j]) < D) uf.merge(i - 1, j - 1);
            }
        }
        int res = uf.distinct();
        cout << res << endl;
    }
}