#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b; cin >> a >> b;
    int n; cin >> n;
    bool ans = false;
    for(int i = 0; i < n; ++i) {
        int s, f; cin >> s >> f;
        ans |= (a <= s && s < b) || (s <= a && a < f);
    }
    cout << ans << endl;
}
