## constant

DELTA = 0.01
DELTA2 = DELTA ** 2

### subroutines

def dist2(v0, v1)
  (v1[0] - v0[0]) ** 2 + (v1[1] - v0[1]) ** 2
end

def i_prod(v0, v1)
  v0[0] * v1[0] + v0[1] * v1[1]
end

def o_prod(v0, v1)
  v0[0] * v1[1] - v0[1] * v1[0]
end

def calc_trglen(trg)
  if trg[3].nil?
    for i in (0..2)
      j = (i + 1) % 3
      trg[i + 3] = Math.sqrt(dist2(trg[i], trg[j]))
    end
  end

  trg[3..5]
end

def trg2rect(trg, d)
  lens = calc_trglen(trg)

  b0 = nil
  b1 = nil
  nv = nil

  for i0 in (0..2)
    i1 = (i0 + 1) % 3
    i2 = (i1 + 1) % 3
    if (lens[i1] - lens[i2]).abs <= DELTA
      b0 = trg[i0]
      b1 = trg[i1]
      nv = [-b1[1] + b0[1], b1[0] - b0[0]]
      v02 = [trg[i2][0] - b0[0], trg[i2][1] - b0[1]]
      nv = [-nv[0], -nv[1]] if i_prod(nv, v02) < 0
      nvlen = Math.sqrt(nv[0] ** 2 + nv[1] ** 2)
      nv[0] *= d / nvlen
      nv[1] *= d / nvlen
    end
  end

  b2 = [b1[0] + nv[0], b1[1] + nv[1]]
  b3 = [b0[0] + nv[0], b0[1] + nv[1]]

  [b0, b1, b2, b3]
end

def inside?(p0, trg)
  lens = calc_trglen(trg)

  op = nil
  for i in (0..2)
    j = (i + 1) % 3
    pv = [p0[0] - trg[i][0], p0[1] - trg[i][1]]
    tv = [trg[j][0] - trg[i][0], trg[j][1] - trg[i][1]]
    op_d = o_prod(pv, tv) / lens[i]
    if op_d.abs > DELTA
      if op.nil?
        op = op_d
      elsif op * op_d < 0
        return false
      end
    end
  end

  #p ["inside?", p0, trg, true]
  true
end

def cross_lines?(u0, u1, v0, v1)
  if dist2(u0, v0) <= DELTA2 || dist2(u0, v1) <= DELTA2 ||
      dist2(u1, v0) <= DELTA2 || dist2(u1, v1) <= DELTA2
    return true
  end

  # x = dux * t + u0x = dvx * s + v0x
  # y = duy * t + u0y = dvy * s + v0y
  # dux * t - dvx * s = v0x - u0x
  # duy * t - dvy * s = v0y - u0y
  # |dux -dvx| |t| = |v0x-u0x|
  # |duy -dvy| |s|   |v0y-u0y|
  # det == dux*(-dvy)-(-dvx)*duy = -dux*dvy+dvx*duy
  # |t| = 1/det * |-dvy dvx| |v0x-u0x|
  # |s|           |-duy dux| |v0y-u0y|

  dux = u1[0] - u0[0]
  duy = u1[1] - u0[1]
  dvx = v1[0] - v0[0]
  dvy = v1[1] - v0[1]

  det = -dux * dvy + dvx * duy
  return false if det == 0

  vux = v0[0] - u0[0]
  vuy = v0[1] - u0[1]

  t = (-dvy * vux + dvx * vuy) / det
  s = (-duy * vux + dux * vuy) / det

  #p ["cl?", u0, u1, v0, v1, t, s]
  t >= 0.0 && t <= 1.0 && s >= 0.0 && s <= 1.0
end

def cross_trgs?(trg0, trg1)
  for i in (0..2)
    return true if inside?(trg0[i], trg1) || inside?(trg1[i], trg0)
  end

  for i0 in (0..2)
    j0 = (i0 + 1) % 3
    for i1 in (0..2)
      j1 = (i1 + 1) % 3
      return true if cross_lines?(trg0[i0], trg0[j0], trg1[i1], trg1[j1])
    end
  end
  false
end

### main

while true
  n, d = gets.strip.split(' ').map{|s| s.to_i}
  break if n == 0 && d == 0

  trgs = []
  n.times do
    pts = gets.strip.split(' ').map{|s| s.to_f}
    trgs << [[pts[0], pts[1]], [pts[2], pts[3]], [pts[4], pts[5]]]
  end
  #p trgs

  rects = trgs.map{|trg| trg2rect(trg, d)}
  #p rects

  origins = n.times.map{true}

  for i in (0...n)
    rct = rects[i]
    rtrg0 = [rct[0], rct[1], rct[2]]
    rtrg1 = [rct[0], rct[2], rct[3]]

    for j in (0...n)
      next if i == j || ! origins[j]

      if cross_trgs?(trgs[j], rtrg0) || cross_trgs?(trgs[j], rtrg1)
        #p [i, j]
        origins[j] = false
        break
      end
    end
  end

  puts origins.select{|tf| tf}.length
end