#include <iostream>
using namespace std;

int main()
{
	int a, b;
	int n;
	bool isDuplicate = false;

	cin >> a >> b;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int s, f;
		cin >> s >> f;

		if (a <= s && s < b) isDuplicate = true;
		if (s <= a && a < f) isDuplicate = true;
		if (a < f && f <= b) isDuplicate = true;
		if (s < b && b <= f) isDuplicate = true;
	}

	cout << isDuplicate << endl;

	return 0;
}