#include<iostream>
using namespace std;

int main(){
    int a,b,N; 
    cin >> a >> b >> N;
    int s[N],f[N];
    for(int i=0;i<N;i++){
        cin >> s[i] >> f[i];
    }
    int flag,fin;
    for(int i=0;i<N;i++){
        if(f[i]<=a){
            flag = 0;
        }else if(b<=s[i]){
            flag = 0;
        }else{
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}
