import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
{
int vertSize;
int horSize;
int firstNumber;
int lastNumber;
Scanner in
= new Scanner
(System.
in); horSize = in.nextInt();
vertSize = in.nextInt();
firstNumber = in.nextInt();
lastNumber= in.nextInt();
if (firstNumber > lastNumber){
int C = firstNumber;
firstNumber = lastNumber;
lastNumber = C;
}
//вычисление координат
int firstNumberx = (firstNumber - 1) % (2 * horSize) + 1;
int firstNumbery = (firstNumber - 1) / (2 * horSize) + 1;
int lastNumberx = (lastNumber - 1) % (2 * horSize) + 1;
int lastNumbery = (lastNumber - 1) / (2 * horSize) + 1;
//создание и задание размера для статического массива
int[] Search= new int[2 * horSize];
Search[firstNumberx - 1] = 0;
int step = 1;
for (int i = firstNumberx - 2; i >= 0; i--){
Search[i] = step++;
}
step = 1;
for (int i = firstNumberx; i < 2 * horSize; i++){
Search[i] = step++;
}
//сравнение по у
for (int j = firstNumbery; j < lastNumbery; j++) {
for (int i = 1; i < 2 * horSize; i += 2) {
Search[i - 1] = Search[i] + 1;
Search[i] += 2;
//определние значения на предпоследнем элементе
if (((i - 2) >= 0) && (Search[i]<Search[i - 2])){
Search[i - 2] = Search[i];
}
}
}
System.
out.
println(Search
[lastNumberx
- 1]); }
}