def a;gets.split.map(&:to_i);end
M=10001
while(n,r=a)!=[0,0]
o=[]
n.times{x,y,t,u=a
(x+1..t).each{|i|l=u-y;o[i*M+y+1,l]=[true]*l}}
p o.count true
p o.each_with_index.inject(0){|s,(b,i)|s+(b ?([o[i-1],o[i+1],o[i-M],o[i+M]].count{|o|!o}):0)}if r==2
end