w = gets.to_i h = gets.to_i n = gets.to_i t = [] n.times do t.push(gets.chomp.split(" ").map(&:to_i)) end a = 0 m = [] mm = [] w.times do |d| p = h - t.map{|u|u[0]}.count(d+1) unless(p == h) a += p m.push(d) mm.push(t.map{|u|u[1]}) end end m.uniq! mm = mm.flatten.uniq a += mm.size * (w - m.size) p a