#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <cassert>

#define REP(i, b, e) for (size_t i = b; i < e; ++i)

size_t insert_x(std::vector<long>& xs, std::vector<std::vector<int> >& map, long x)
{
	std::vector<long>::iterator it = std::lower_bound(xs.begin(), xs.end(), x);

	const size_t i = it - xs.begin();

	if (*it != x)
	{
		xs.insert(it, x);

		assert(i >= 1);

		map.insert(map.begin() + i, map[i - 1]);
	}

	return i;
}

size_t insert_y(std::vector<long>& ys, std::vector<std::vector<int> >& map, long y)
{
	std::vector<long>::iterator it = std::lower_bound(ys.begin(), ys.end(), y);

	const size_t i = it - ys.begin();

	if (*it != y)
	{
		ys.insert(it, y);

		assert(i >= 1);

		REP(j, 0, map.size())
		{
			map[j].insert(map[j].begin() + i, map[j][i - 1]);
		}
	}

	return i;
}

int main()
{
	long w, h;

	std::cin >> w >> h;

	assert(0 <= w && w <= 1000000);
	assert(0 <= h && h <= 1000000);

	size_t n;

	std::cin >> n;

	assert(1 <= n && n <= 1000);

	std::vector<long> xs(2); xs[0] = 0; xs[1] = w;

	std::vector<long> ys(2); ys[0] = 0; ys[1] = h;

	std::vector<std::vector<int> > map(1, std::vector<int>(1, true));

	for (; n; --n)
	{
		long left, bottom, right, top; // masking tape

		std::cin >> left >> bottom >> right >> top;

		assert(left < right);

		assert(bottom < top);

		const size_t lower_xi = insert_x(xs, map, left);

		const size_t upper_xi = insert_x(xs, map, right);

		const size_t lower_yi = insert_y(ys, map, bottom);

		const size_t upper_yi = insert_y(ys, map, top);

		REP(xi, lower_xi, upper_xi) REP(yi, lower_yi, upper_yi)
		{
			map[xi][yi] = false;
		}
	}

	const size_t xn = xs.size() - 1;

	const size_t yn = ys.size() - 1;

	size_t count = 0;

	REP(xi, 0, xn) REP(yi, 0, yn) if (map[xi][yi])
	{
		++count;

		std::queue<std::pair<size_t, size_t> > q;

#define PUSH(XI, YI) if (map[XI][YI]) { map[XI][YI] = false; q.push(std::make_pair(XI, YI)); }

		PUSH(xi, yi);

		while (! q.empty())
		{
			const size_t xj = q.front().first;

			const size_t yj = q.front().second;

			q.pop();

			if (xj >= 1) // left
			{
				PUSH(xj - 1, yj);
			}

			if (yj >= 1) // top
			{
				PUSH(xj, yj - 1);
			}

			if (xj + 1 < xn) // right
			{
				PUSH(xj + 1, yj);
			}

			if (yj + 1 < yn) // bottom
			{
				PUSH(xj, yj + 1);
			}
		}

#undef PUSH

	}

	std::cout << count << std::endl;
}

