#include<bits/stdc++.h> usingnamespace std; constint N = 100001; int n, s, t, res; vector<pair<int,int>> v; #define MIN_INF -2e9 intmain(){ scanf("%d%d%d", &s, &t, &n); int r = MIN_INF, l = MIN_INF; for(int i = 0; i < n; ++i) { int a, b; scanf("%d%d", &a, &b); v.push_back(make_pair(a, b)); } sort(v.begin(), v.end());
bool success = false; for(int i = 0; i < n; ++i) { int j = i, tmp_r = MIN_INF; while(j < n && v[j].first <= s) { tmp_r = max(tmp_r, v[j].second); j++; } if(tmp_r < s) { res = -1; break; } res++; if(tmp_r >= t) { success = true; break; } s = tmp_r; i = j - 1; } if(!success) printf("-1"); elseprintf("%d", res); return0; }