#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e,count;
    cin>>a>>b>>c;
    count=0;
    for(int j=1;j<=c;j++){
        cin>>d>>e;
        if(a>d&&a<e){
            count=1;
        }else if(b>d&&b<e){
            count=1;
        }else if(a==d&&b==e){
            count=1;
        }else if(a<d&&b>e){
            count=1;
        }
    }
    cout<<count<<endl;
}

