### constant

N = 1001

### subroutines

def make_fibo(v)
  f0 = f1 = 1
  fibos = []
  v.times do
    f = (f0 + f1) % N
    fibos << f
    f0, f1 = f1, f
  end
  fibos
end

### main

while line = gets
  v, d = line.split.map(&:to_i)

  fibos = make_fibo(v)

  $nbrs = v.times.map{[]}

  for i in (0...(v - 1))
    for j in ((i + 1)...v)
      if (fibos[i] - fibos[j]).abs < d
        $nbrs[i] << j
        $nbrs[j] << i
      end
    end
  end
  #p $nbrs

  count = 0
  used = v.times.map{false}

  for i in (0...v)
    if ! used[i]
      count += 1
      used[i] = true
      q = [i]

      while ! q.empty?
        u = q.shift
        for v in $nbrs[u]
          if ! used[v]
            used[v] = true
            q << v
          end
        end
      end
    end
  end

  puts count
end