#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int st, ed, n;
struct Range{
int l, r;
bool operator < (const Range &W)const{
return l < W.l;
}
}range[N];
int main(){
cin >> st >> ed;
cin >> n;
for(int i = 0; i < n; i ++ ){
cin >> range[i].l >> range[i].r;
}
sort(range, range + n);
bool flag = false;
int res = 0;
for(int i = 0; i < n; i ++ ){
int j = i, r = - 2e9;
while(j < n && range[j].l <= st){
r = max(r, range[j].r);
j ++;
}
if(r < st){
res = -1;
break;
}
res ++ ;
if(r >= ed){
flag = true;
break;
}
st = r;
i = j - 1;
}
if(!flag){
res = -1;
}
cout << res << endl;
return 0;
}