class Array
	def bsearch(l = 0, r = size - 1, &pred)
		if r - l < 10
			return (l..r).find{|j| pred[self[j]]}
		end

		c = (l + r) / 2 
		if pred[self[c]]
			bsearch(l, c-1, &pred) || c
		else
			bsearch(c+1, r, &pred)
		end
	end
end

class Line
	def initialize(*args)
		@x1, @y1, @x2, @y2 = args
	end
	attr_reader :x1, :y1, :x2, :y2
end

class IntervalTree
	def initialize(l, r)
		@l = l
		@r = r
		@c = (l + r) / 2
		@left_child = @right_child = nil
		@start_sorted = []
		@end_sorted = []
	end

	def add(l, r, x)
		if r < @c
			@left_child ||= self.class.new(l, @c - 1)
			@left_child.add(l, r, x)
		elsif @c < l
			@right_child ||= self.class.new(@c + 1, r)
			@right_child.add(l, r, x)
		else
			i = @start_sorted.bsearch{|p, q, _| p >= l} || @start_sorted.size
			@start_sorted.insert(i, [l, r, x])
			i = @end_sorted.bsearch{|p, q, _| q >= r} || @end_sorted.size
			@end_sorted.insert(i, [l, r, x])
		end
	end

	def query(x)
		if x < @c
			ans = @start_sorted.take_while{|l, r| l <= x} 
			ans += @left_child.query(x) if @left_child
			ans
		elsif x > @c
			ans = []
			ans += @right_child.query(x) if @right_child
			i = @end_sorted.bsearch{|l, r| x <= r}
			ans += @end_sorted[i..-1] if i
			ans
		else
			@start_sorted
		end
	end
end

class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		u.parent = v.root
		v.size += u.size
	end

	def same?(x, y)
		return false unless u = @obj_to_node[x]
		return false unless v = @obj_to_node[y]
		u.root == v.root
	end

	def root_of(x)
		v = @obj_to_node[x]
		v ? v.root : nil
	end
end


uf = UnionFind.new

w, h, n = gets.split.map(&:to_i)
v_tree = IntervalTree.new(0, 10**9)
h_tree = IntervalTree.new(0, 10**9)
v_line = {}
h_line = {}

l1 = Line.new(0,0,w,0)
l2 = Line.new(0,h,w,h)
l3 = Line.new(0,0,0,h)
l4 = Line.new(w,0,w,h)

h_line[[0,w,0]] = l1
h_line[[0,w,h]] = l2
v_line[[0,h,0]] = l3
v_line[[0,h,w]] = l4

uf.union(l1, l2)
uf.union(l1, l3)
uf.union(l1, l4)

h_tree.add(0, w, 0)
h_tree.add(0, w, h)
v_tree.add(0, h, 0)
v_tree.add(0, h, w)

count = 1
n.times {
	x1, y1, x2, y2 = gets.split.map(&:to_i)

	if x1 == x2
		#puts "added: v (#{x1}, #{y1}, #{x2}, #{y2})"
		a = h_tree.query(x1).map{|x| h_line[x]}
		a = a.select{|line| y1 <= line.y1 && line.y2 <= y2}
		#p a

		group_count = Hash.new(-1)
		a.each{|hl| group_count[uf.root_of(hl)] += 1}
		#p group_count.values
		count += group_count.values.inject(0, :+)

		l = Line.new(x1, y1, x2, y2)
		v_line[[y1, y2, x1]] = l
		a.each{|hl| uf.union(l, hl)}
		v_tree.add(y1, y2, x1)
	end

	if y1 == y2
		#puts "added: h (#{x1}, #{y1}, #{x2}, #{y2})"
		a = v_tree.query(y1).map{|x| v_line[x]}
		a = a.select{|line| x1 <= line.x1 && line.x2 <= x2}
		#p a

		group_count = Hash.new(-1)
		a.each{|vl| group_count[uf.root_of(vl)] += 1}
		#p group_count.values
		count += group_count.values.inject(0, :+)

		l = Line.new(x1, y1, x2, y2)
		h_line[[x1, x2, y1]] = l
		a.each{|vl| uf.union(l, vl)}
		h_tree.add(x1, x2, y1)
	end

	#puts
}

p count