class LazySegmentTree
	def initialize(n, l = 0, r = n-1)
		@range_min = l
		@range_max = r
		@start = 0
		@between = 0
		@end = 0
		if l == r
		else
			c = (l + r) / 2
			@left_child = self.class.new(n, l, c)
			@right_child = self.class.new(n, c+1, r)
		end
	end

	attr_reader :range_min, :range_max

	def add_start(x, bits)
		if @range_min == @range_max
			@start |= bits
		else
			force
			if x <= @left_child.range_max
				@left_child.add_start(x, bits)
			else
				@right_child.add_start(x, bits)
			end
		end
	end

	def add_end(x, bits)
		if @range_min == @range_max
			@end |= bits
		else
			force
			if x <= @left_child.range_max
				@left_child.add_end(x, bits)
			else
				@right_child.add_end(x, bits)
			end
		end
	end

	def add_between(x, y, bits)
		return if x > y

		if x == @range_min && y == @range_max
			@between |= bits
		else
			force
			lr = @left_child.range_max
			@left_child.add_between(x, lr < y ? lr : y, bits)
			rl = @right_child.range_min
			@right_child.add_between(rl > x ? rl : x, y, bits)
		end
	end

	def force
		if @range_min != @range_max
			@left_child.take(@start, @between, @end)
			@right_child.take(@start, @between, @end)
		end
		@star = @between = @end = 0
	end

	def take(start, between, finish)
		@start |= start
		@between |= between
		@end |= finish
	end

	def net_start_count(x)
		if @range_min == @range_max
			bits = @start
			bits -= bits & @end
			bits -= bits & @between
			bits.to_s(2).count("1")
		else
			force
			if x <= @left_child.range_max
				@left_child.net_start_count(x)
			else
				@right_child.net_start_count(x)
			end
		end
	end

	def net_end_count(x)
		if @range_min == @range_max
			bits = @end
			bits -= bits & @start
			bits -= bits & @between
			bits.to_s(2).count("1")
		else force
			if x <= @left_child.range_max
				@left_child.net_end_count(x)
			else
				@right_child.net_end_count(x)
			end
		end
	end
end


ones = [0]
10000.times{
	ones << ((ones[-1] << 1) | 1)
}

t = Time.new

loop {
	n, r = gets.split.map(&:to_i)
	break if n == 0

	v_st = LazySegmentTree.new(10001)
	h_st = LazySegmentTree.new(10001)

	n.times {
		x1, y1, x2, y2 = gets.split.map(&:to_i)
		bits = ones[y2-y1] << y1
		v_st.add_start(x1, bits)
		v_st.add_between(x1+1, x2-1, bits) if x1+1 < x2
		v_st.add_end(x2, bits)
		bits = ones[x2-x1] << x1
		h_st.add_start(y1, bits)
		h_st.add_between(y1+1, y2-1, bits) if y1+1 < y2
		h_st.add_end(y2, bits)
	}

	area = 0
	for i in 0..1000
		area += v_st.net_start_count(i) * (1000-i)
		area -= v_st.net_end_count(i) * (1000-i)
	end
	p area

	if r == 2
		len = 0
		for i in 0..1000
			len += v_st.net_start_count(i)
			len += v_st.net_end_count(i)
			len += h_st.net_start_count(i)
			len += h_st.net_end_count(i)
		end
		p len
	end
}