N = 1001

def init_fib
  fib = Array.new(1002)
  fib[0] = 1
  fib[1] = 2
  2.upto(N) do |i|
    fib[i] = (fib[i-1] + fib[i-2]) % N
  end
  fib
end

def root(tree, i)
  if tree[i] == i
    i
  else
    root(tree, tree[i])
  end
end

if __FILE__ == $0
  fib = init_fib
  STDIN.each_line do |input|
    count = 0
    v, d = input.split.map(&:to_i)
    tree = Array.new(v+1)
    0.upto(v) do |i|
      tree[i] = i
    end

    1.upto(v) do |i|
      (i+1).upto(v) do |j|
        tree[j] = root(tree, i) if (fib[j] - fib[i]).abs < d
      end
    end
    1.upto(v) do |i|
      count += 1 if root(tree, i) == i
    end
    puts count.to_s
  end
end