#include #define INF 1000000001LL #define MOD 1000000007LL #define long long long #define all(x) x.begin(),x.end() using namespace std; vector graph[100003]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,a,b; cin >> n >> m >> a >> b; for(int i = 0; i> x >> y; y++; if(x < a) x = a; if(x > b+1) x = b+1; if(y < a) y = a; if(y > b+1) y = b+1; graph[x].push_back(y); graph[y].push_back(x); } queue q; vector vis(n+2); q.push(a); vis[a] = 1; while(!q.empty()) { int x = q.front(); q.pop(); for(int y : graph[x]) { if(vis[y]) continue; vis[y] = vis[x]+1; q.push(y); } } cout << vis[b+1]-1 << endl; return 0; }