while gets
  V, d = $_.split.map(&:to_i)
  arr = Array.new
  pre = cur = 1
  V.times do
    arr << (fwd = (pre + cur) % 1001)
    pre = cur
    cur = fwd
  end
  p arr.sort!.zip(arr[1,V])[0,V-1].count{|v| v[1] - v[0] >= d} + 1
end