#include <iostream>
using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;

  int N;
  cin >> N;

  int s[100], f[100];
  for(int i=0; i<N; i++){
    cin >> s[i] >> f[i];
  }

  int dup = 0;
  for(int i=0; i<N; i++){
    if(b<=s[i] || a>=f[i]){
      dup++;
    }
  }
  
  if(dup==N){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }

  return 0;
}

