#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
vector<ll> L(2005, -1), R(2005,- 1); ll number;
void init(int N, int H[]) {
number = N;
set<pair<ll, ll>> S;
for (int i=0; i<N; i++) {
auto it = S.upper_bound({H[i], 0});
if (it != S.end())
L[i] = (*it).second;
S.insert({H[i], i});
}
S.clear();
for (int i=N-1; i>=0; i--) {
auto it = S.upper_bound({H[i], 0});
if (it != S.end())
R[i] = (*it).second;
S.insert({H[i], i});
}
}
ll dist[2005];
int minimum_jumps(int A, int B, int C, int D) {
for (int i=0; i<number; i++) {dist[i] = -1;}
queue<int> Q;
for (int i=A; i<=B; i++) {
Q.push(i); dist[i] = 0;
}
while (!Q.empty()) {
ll front = Q.front(); Q.pop();
if (C <= front && front <= D) {
return dist[front];
}
if (L[front] != -1) {
if (dist[L[front]] == -1) {
Q.push(L[front]); dist[L[front]] = dist[front] + 1;
}
}
if (R[front] != -1) {
if (dist[R[front]] == -1) {
Q.push(R[front]); dist[R[front]] = dist[front] + 1;
}
}
}
return -1;
};
// int main() {
// cin.tie(0); ios_base::sync_with_stdio(0);
// int j[] = {3, 2, 1, 6, 4, 5, 7};
// init(7, j);
// cout << minimum_jumps(4, 4, 6, 6) << '\n';
// return 0;
// }