#include <bits/stdc++.h>

using namespace std;

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

  bool ok = true;
  for (int i = 0; i < n; i++) {
    int s, f;
    cin >> s >> f;
    ok &= (b <= s || f <= a);
  }

  cout << !ok << endl;

  return 0;
}
