#include <bits/stdc++.h>
using namespace std;
int Num[6];
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  a--;
  b--;
  n--;
  int Ans = 0;
  int Start = a / m;
  int End = b / m;
  if (End - Start > 1) Ans++;
  if (a % m != 0) Ans++;
  if (b % m != m - 1 && b != n) Ans++;
  if (End - Start == 1 && a % m == 0 && b % m == m - 1)
    Ans = 1;
  else if (End - Start == 1)
    Ans = 2;
  if (b == n && a % m != 0)
    Ans = 2;
  else if (b == n)
    Ans = 1;
  if (End == Start) Ans = 1;
  int Ans2 = 3;
  if (a % m == b % m + 1) Ans2 = 2;
  int Put = min(Ans, Ans2);
  if (Put == 0) Put = 1;
  cout << Put;
  return 0;
}
