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{|a| a[1] - a[0] >= d} + 1
end