#include <iostream>
#include <algorithm>
using namespace std;
int main (){
int a,b;
int n;
cin >> a >> b >> n;
int s[200],t[200],x[2000];
x[a]=1;
x[b+1]=-1;
for(int i=1;i<=n;i++){
    cin >> s[i] >> t[i];
    x[s[i]]=1;
    if(a>=s[i]&&a<t[i]){
        cout << 1 << endl;
        return 0;
    }
}
for(int i=a+1;i<b;i++){
   
     if(x[i]==1){
        cout << 1 << endl;
        return 0;
    }
   
   
}
cout << 0 << endl;
    return 0;
}
