#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  int xa, ya, xb, yb;
  cin >> n >> m >> a >> b;
  a--;
  b--;
  xa = a / m;
  ya = a % m;
  xb = b / m;
  yb = b % m;
  int ans;
  if (xa == xb || (!ya && yb == m - 1) || (!ya && b == n - 1))
    ans = 1;
  else if (xb == xa + 1)
    ans = 2;
  else if (b == n - 1) {
    if (!ya)
      ans = 1;
    else
      ans = 2;
  } else if (!ya || yb == m - 1)
    ans = 2;
  else if (yb == ya - 1)
    ans = 2;
  else
    ans = 3;
  cout << ans << endl;
  return 0;
}
