#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main(void){
	int a,b,N,s,f,ans=0;
	cin>>a>>b>>N;
	for(int i=0;i<N;i++)
	{
		cin>>s>>f;
		if(a<=s&&s<b)
		{
			ans=1;
		}
		if(a<f&&f<=b)
		{
			ans=1;
		}
		if(s<=a&&a<f)
		{
			ans=1;
		}
		if(s<b&&b<=f)
		{
			ans=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}
