#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int a, b, n;
  cin >> a >> b >> n;
  int s, f;
  int i;
  for (i = 0; i < n; i++) {
    cin >> s >> f;
    if ((s < b && b <= f) || (s <= a && a < f) || (s <= a && b <= f) || (a <= s && f <= b)) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}

