m=Array.new(10001){Array.new(10001){0}}
def a;gets.split.map(&:to_i);end
n,r=a
n.times{x,y,t,u=a
(x...t).each{|i|(y...u).each{|j|m[i][j]=1}}}
p m.flatten.count 1
p (0...10000).inject(0){|s,i|s+(0...10000).inject(0){|d,j|d+((m[i][j]==0)?0:(4-m[i-1][j]-m[i+1][j]-m[i][j-1]-m[i][j+1]))}} if r==2