#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int s, f;
        cin >> s >> f;
        if (b <= s || f <= a) {
            continue;
        }
        else {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}
