#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
int n, m, o, a, b, ans = 0, A[1010], B[1010];
int main() {
	cin >> n >> m >> o;
	rep(i, o) {
		cin >> A[i] >> B[i];
		if (n > A[i] && n < B[i]) ans = 1;
		else if (m > A[i] && m < B[i]) ans = 1;
		else if (n < A[i] && m > B[i]) ans = 1;
		else if (n == A[i] || m == B[i]) ans = 1;
	}
	cout << ans << endl;
	return 0;
}
