#include using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector #define mat vector > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef long double ld; typedef complex comp; const ll INF=1e9+7; const ll inf=INF; const ll MOD=998244353; const ll mod=MOD; const int MAX=200010; signed main(){ ll n,m,a,b;cin>>n>>m>>a>>b; vectorp(m); vectorq(m); rep(i,m){ cin>>p[i].fi>>p[i].se; q[i].se=p[i].fi,q[i].fi=p[i].se; } sort(all(p)); sort(rall(q)); vectordp(n+2,0); REP(i,a,n+2)dp[i]=inf; rep(i,m){ dp[p[i].se]=min(dp[p[i].se],dp[p[i].fi-1]+1); } rep(i,m){ dp[q[i].se-1]=min(dp[q[i].se-1],dp[q[i].fi]+1); } rep(i,m){ dp[p[i].se]=min(dp[p[i].se],dp[p[i].fi-1]+1); } ll ans=inf; REP(i,b,n+2)ans=min(ans,dp[i]); if(ans==inf){ cout<<-1<